Last active
March 8, 2021 14:00
-
-
Save deanwampler/2f4381c75b5cf795be84d8759c5755fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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