Created
July 13, 2011 18:35
-
-
Save debasishg/1080967 to your computer and use it in GitHub Desktop.
samples of monad transformers in scalaz
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> List(10, 12).transLift[OptionT].runT | |
res12: List[Option[Int]] = List(Some(10), Some(12)) | |
scala> optionT(List(some(12), some(50))).runT | |
res13: List[Option[Int]] = List(Some(12), Some(50)) | |
scala> List(some(12), some(50)) | |
res14: List[Option[Int]] = List(Some(12), Some(50)) | |
scala> optionT(List(some(12), some(50))) | |
res15: scalaz.OptionT[List,Int] = scalaz.OptionTs$$anon$1@1541633 | |
scala> res15 existsT (_ == 12) | |
res16: List[Boolean] = List(true, false) | |
scala> res15.map(_ * 2) | |
res17: scalaz.OptionT[List,Int] = scalaz.OptionTs$$anon$1@3e6d51 | |
scala> res15.map(_ * 2).runT | |
res18: List[Option[Int]] = List(Some(24), Some(100)) | |
scala> List(10, 12).transLift[OptionT].map(_ * 2).runT | |
res19: List[Option[Int]] = List(Some(20), Some(24)) | |
scala> some(12).transLift[OptionT].map(_ * 2).runT | |
res20: Option[Option[Int]] = Some(Some(24)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment