Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
val listFunctor = new Functor[List] {
override def map[A, B](fa: List[A])(f: A => B): List[B] = fa match {
case Nil => Nil
case h :: t => f(h) :: map(t)(f)
}
}
val ints = List(1, 2, 3, 4, 5, 6)
listFunctor.map(ints)(_.toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment