Skip to content

Commit

Permalink
Extensions for usability
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed Sep 16, 2012
1 parent abe1e0c commit 723a712
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Example/Program.boo
Expand Up @@ -2,13 +2,27 @@ namespace Example

import System
import Boo.Lang.Extensions
import FSharpx
import Boo.Lang from Boo.Lang

[Extension]
def Get[of S,D](lens as Lens[of S,D], source as S) as D:
return lens.Get.Invoke(source)

[Extension]
def Set[of S,D](lens as Lens[of S,D], source as S, newValue as D) as S:
return lens.Set.Invoke(newValue).Invoke(source)

[Extension]
def Update[of S,D](lens as Lens[of S,D], source as S, update as Func[of D,D]) as S:
fupdate = FSharpFunc.FromFunc(update)
return lens.Update(fupdate, source)

record Person:
Name as string
Value as int

p = Person("john", 23)
print p.Name
print Person.NameLens.Get.Invoke(p)
print p.GetHashCode()
print Person.NameLens.Get(p)
Console.ReadKey()

0 comments on commit 723a712

Please sign in to comment.