Created
February 14, 2022 20:04
-
-
Save reevik/53d6506678289357289418f245fc83a0 to your computer and use it in GitHub Desktop.
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
// "x => x + 1" could be reduced to "_ + 1" using placeholder syntax. | |
> Some(10) flatMap(x => x + 1) | |
res0: Option[Int] = Some(45) | |
> Some(10) flatMap(x => None) | |
res0: Option[Nothing] = None | |
> List(Some(1), None, Some(3), None).map(a => \ | |
a.flatMap(b => Some(b + 1))) | |
res0: List[Option[Int]] = List(Some(2), None, Some(4), None) | |
// if you want to get the list of Ints | |
> List(Some(1), None, Some(3), None).map(a => \ | |
a.flatMap(b => Some(b + 1))) | |
flatten |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment