Created
April 12, 2020 17:14
-
-
Save p-pavel/465258ec4741bc625b46a85ebc5ea309 to your computer and use it in GitHub Desktop.
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
enum Maybe[+A]: | |
case Just(a:A) | |
case None | |
given Functor[Maybe]: | |
def [A,B](fa: Maybe[A]).map(f: A ⇒ B): Maybe[B] = | |
import Maybe._ | |
fa match | |
case Just(a) ⇒ Just(f(a)) | |
case None ⇒ None | |
given Monad[Maybe]: | |
import Maybe._ | |
val functor = summon[Functor[Maybe]] | |
def pure[A](a: A) = Just(a) | |
def [A](ffa: Maybe[Maybe[A]]).join = | |
ffa match | |
case Just(ma) ⇒ ma | |
case None ⇒ None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment