Created
May 16, 2012 15:35
-
-
Save rirakkumya/2711351 to your computer and use it in GitHub Desktop.
[scala] Eitherのサンプル
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> val l = Left(3) | |
l: Left[Int,Nothing] = Left(3) | |
scala> val r = Right(3) | |
r: Right[Nothing,Int] = Right(3) | |
scala> def calc = (x:Either[Int,Int]) => x.right.map(_ + 2).left.map(_ * 2).right.map(_ + 3) | |
culc: Either[Int,Int] => Product with Either[Int,Int] with Serializable | |
scala> calc(r) | |
res10: Product with Either[Int,Int] with Serializable = Right(8) | |
scala> calc(l) | |
res11: Product with Either[Int,Int] with Serializable = Left(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment