Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Last active March 8, 2021 14:05
Show Gist options
  • Save deanwampler/77a0158ab8bbc0ba35d631b7d02ed266 to your computer and use it in GitHub Desktop.
Save deanwampler/77a0158ab8bbc0ba35d631b7d02ed266 to your computer and use it in GitHub Desktop.
scala> given [L]: Functor[({type λ[α] = Either[L,α]})#λ] with
| extension [R1] (either: Either[L,R1])
| def map2[R2](f: R1 => R2): Either[L,R2] = either map f
|
// defined class given_Functor_R1_λ
scala> Right(2).map2(_ * 2.2)
val res0: Either[Nothing, Double] = Right(4.4)
scala> Left[String,Int]("fail!").map2(_ * 2.2)
val res1: Either[String, Double] = Left(fail!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment