Created
November 25, 2015 16:26
-
-
Save rahilb/372d8e34e1669013c9c8 to your computer and use it in GitHub Desktop.
Functor Abstraction Pattern
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 cats.Functor | |
trait ImplicitInstances { | |
implicit val OptionInstance: Functor[Option] = new Functor[Option] { | |
override def map[A, B](fa: Option[A])(f: (A) => B): Option[B] = fa.map(f) | |
} | |
} | |
final class FuncAbs[M[_]] { | |
def double(s: M[String])(implicit functor : Functor[M]) = functor.map(s)(str => str + str) | |
} | |
object Main extends App with ImplicitInstances { | |
val opt = new FuncAbs[Option] | |
val dub = opt.double(Some("foo")) | |
println(dub) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment