Skip to content

Instantly share code, notes, and snippets.

@sderosiaux
Created December 14, 2017 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sderosiaux/ed2311d21c0010a432c4e02e120727a6 to your computer and use it in GitHub Desktop.
Save sderosiaux/ed2311d21c0010a432c4e02e120727a6 to your computer and use it in GitHub Desktop.
How to make infix stuff in Scala
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