Created
May 24, 2018 18:04
-
-
Save harmeetsingh0013/357c784bdc641bf8c531b574e4682d49 to your computer and use it in GitHub Desktop.
This file contains 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
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