Last active
August 23, 2018 19:16
-
-
Save LeifW/aefafa577b294a3fdd2b03cf39153cbc to your computer and use it in GitHub Desktop.
Scala do-notation overloading
This file contains 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
case class Foo(a: Int) { | |
def map(f : Int => Int) = Foo(f(a)) | |
def flatMap(f : Int => Bar): Bar = f(a) | |
} | |
case class Bar(a: Int) { | |
def map(f : Int => Int) = Bar(f(a)) | |
def flatMap(f : Int => Bar): Bar = f(a) | |
} | |
object Main { | |
val foo: Bar = for { | |
x <- Foo(1) | |
y <- Bar(x) | |
} yield y | |
def main(args: Array[String]): Unit = println(foo) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment