Created
December 14, 2017 23:53
-
-
Save sderosiaux/ed2311d21c0010a432c4e02e120727a6 to your computer and use it in GitHub Desktop.
How to make infix stuff in Scala
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 Toto[F[_]] { | |
def hello[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
implicit val Fun = new Toto[List] { | |
override def hello[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f) | |
} | |
implicit class FunImplicits[F[_], A](t: F[A]) { | |
def !!!![B](f: A => B)(implicit toto: Toto[F]): F[B] = toto.hello(t)(f) | |
} | |
val l = List(1, 2, 3) | |
val res = l !!!! ((x: Int) => x * 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment