Created
November 10, 2014 10:23
-
-
Save prassee/7576487f1213ce3407c7 to your computer and use it in GitHub Desktop.
Mona-d-emo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Monademo extends App { | |
val f = new Foo("foo") | |
val br = new Bar(f) | |
val bs = new Bas(br) | |
def evalBas(bs: Bas) = { | |
for { | |
b <- bs.getBar | |
c <- b.getFoo | |
} yield c.getName | |
} | |
println(evalBas(bs).getOrElse("No Foo")) | |
} | |
class Foo(name: String) { | |
def getName = name | |
} | |
class Bar(foo: Foo) { | |
def getFoo = Some(foo) | |
} | |
class Bas(bar: Bar) { | |
def getBar = Some(bar) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment