Skip to content

Instantly share code, notes, and snippets.

@p-pavel
Created April 12, 2020 17:14
Show Gist options
  • Save p-pavel/465258ec4741bc625b46a85ebc5ea309 to your computer and use it in GitHub Desktop.
Save p-pavel/465258ec4741bc625b46a85ebc5ea309 to your computer and use it in GitHub Desktop.
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