Created
September 11, 2019 04:58
-
-
Save justinhj/dba9613eb3d169508a307c1f90a5b84e to your computer and use it in GitHub Desktop.
List and Option in for
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
// Ammonite repl output | |
@ desugar { | |
for ( | |
s <- List(1,2,3); | |
o <- if(s % 2 == 1) Some(s) else None | |
) yield (s + o) | |
} | |
res12: Desugared = scala.collection.immutable.List.apply[Int](1, 2, 3).flatMap[Int, Any](((s: Int) => scala.Option.option2Iterable[Int]((if (s.%(2).==(1)) | |
scala.Some.apply[Int](s) | |
else | |
scala.None).map[Int](((o: Int) => s.+(o))))))(scala.collection.immutable.List.canBuildFrom[Int]) | |
// Cleaned up | |
List.apply[Int](1, 2, 3).flatMap[Int, Any](((s: Int) => Option.option2Iterable[Int]( | |
(if (s.%(2).==(1)) | |
Some.apply[Int](s) | |
else | |
None). | |
map[Int](((o: Int) => s.+(o))))))(List.canBuildFrom[Int] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment