Skip to content

Instantly share code, notes, and snippets.

@hexx
Created February 22, 2013 05:26
Show Gist options
  • Save hexx/5010946 to your computer and use it in GitHub Desktop.
Save hexx/5010946 to your computer and use it in GitHub Desktop.
Option fold problem
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