Created
February 22, 2013 05:26
-
-
Save hexx/5010946 to your computer and use it in GitHub Desktop.
Option fold problem
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
scala> Some(1).map(_ :: Nil) getOrElse Nil | |
res0: List[Int] = List(1) | |
scala> Some(1).fold(Nil)(_ :: Nil) | |
<console>:8: error: type mismatch; | |
found : List[Int] | |
required: scala.collection.immutable.Nil.type | |
Some(1).fold(Nil)(_ :: Nil) | |
^ | |
scala> Some(1).fold(Nil: List[Int])(_ :: Nil) | |
res2: List[Int] = List(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment