chtefi
12/14/2017 - 11:53 PM

How to make infix stuff in Scala

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)