Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Last active March 8, 2021 14:00
Show Gist options
  • Save deanwampler/2f4381c75b5cf795be84d8759c5755fb to your computer and use it in GitHub Desktop.
Save deanwampler/2f4381c75b5cf795be84d8759c5755fb to your computer and use it in GitHub Desktop.
// Adapted from:
// https://github.com/deanwampler/programming-scala-book-code-examples/blob/master/src/main/scala/progscala3/typesystem/typelambdas/Functor.scala
trait Functor[M[_]]:
extension [A] (m: M[A]) def map2[B](f: A => B): M[B]
given Functor[Seq] with
extension [A] (seq: Seq[A]) def map2[B](f: A => B): Seq[B] = seq map f
given Functor[Option] with
extension [A] (opt: Option[A]) def map2[B](f: A => B): Option[B] = opt map f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment