Skip to content

Instantly share code, notes, and snippets.

@harmeetsingh0013
Created May 24, 2018 18:04
Show Gist options
  • Save harmeetsingh0013/357c784bdc641bf8c531b574e4682d49 to your computer and use it in GitHub Desktop.
Save harmeetsingh0013/357c784bdc641bf8c531b574e4682d49 to your computer and use it in GitHub Desktop.
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