Option semi-comonad ?
| case class MyOption[A](o: Option[A]) { | |
| def map[B](f: A => B): MyOption[B] = | |
| MyOption(o map f) | |
| def flatMap[B](f: A => MyOption[B]): MyOption[B] = | |
| MyOption(o flatMap (f(_).o)) | |
| def coflatten: MyOption[MyOption[A]] = | |
| MyOption(o match { | |
| case None => None | |
| case Some(a) => Some(MyOption(Some(a))) | |
| }) | |
| def coflatMap[B](f: MyOption[A] => B): MyOption[B] = | |
| coflatten map f | |
| def coflatten_? : MyOption[MyOption[A]] = | |
| MyOption(Some(MyOption(o))) | |
| def coflatMap_?[B](f: MyOption[A] => B): MyOption[B] = | |
| coflatten_? map f | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment