Created
March 3, 2015 17:58
-
-
Save gakuzzzz/78f52e39d8275309df8a to your computer and use it in GitHub Desktop.
Option.apply の使いどころ
This file contains hidden or 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> val f: (Option[Int], Int) => Option[Int] = _ orElse Some(_) | |
f: (Option[Int], Int) => Option[Int] = <function2> | |
scala> val seq: Seq[Int] = Seq(1,2,3) | |
seq: Seq[Int] = List(1, 2, 3) | |
scala> seq.foldLeft(Some(0))(f) | |
<console>:10: error: type mismatch; | |
found : (Option[Int], Int) => Option[Int] | |
required: (Some[Int], Int) => Some[Int] | |
seq.foldLeft(Some(0))(f) | |
^ | |
scala> seq.foldLeft(Option(0))(f) | |
res1: Option[Int] = Some(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment