Created
December 23, 2013 21:00
-
-
Save noahlz/8104479 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
// Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_15). | |
// Type in expressions to have them evaluated. | |
// Type :help for more information. | |
def foo(n: Int) = Some(n) | |
// foo: (n: Int)Some[Int] | |
List(1,2,3,4).map(foo(_)) | |
// res2: List[Some[Int]] = List(Some(1), Some(2), Some(3), Some(4)) | |
List(1,2,3,4).flatMap(foo(_)) | |
// res3: List[Int] = List(1, 2, 3, 4) | |
List(1,2,3,4).flatMap(foo(_).toList) | |
// res4: List[Int] = List(1, 2, 3, 4) | |
// Extra fun! | |
List(1,2,3,4).toSet() | |
// res5: Boolean = false | |
List(1,2,3,4).toSet | |
// res6: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4) | |
```` |
@ericacm Some have told me that the presence of that implicit is the "bug" (I.e. another strike against scala, making it broken as a functional language?). The toSet() thing is some kind of syntax idiosyncrasy, supposedly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
flatMap
works because ofOption.option2iterable
.I think
List(1,2,3,4).toSet() == false
is a bug.