Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List and Option in for
// 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
You can’t perform that action at this time.