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
import scala.language.higherKinds | |
object TypeClasses { | |
// applies to type constructors (F[_]) | |
trait Functor[F[_]] { | |
def map[A, B](xs: F[A])(f: A => B): F[B] | |
} | |
implicit object ListFunctor extends Functor[List] { | |
override def map[A, B](xs: List[A])(f: A => B): List[B] = xs.map(f) | |
} | |
implicit object OptionFunctor extends Functor[Option] { |