It is required to refer to something exactly twice, often enough so that it is useful to enrich it in the method:
implicit class DiamondMapper[A](val a: A) extends AnyVal { def diamond[B](f: (A,A) => B) = f(a,a) }
Then:
scala> 575.toString.diamond(_ == _.reverse) res1: Boolean = true
This is a special case of the pipe operator ( |> if you like symbolic notation), but it is a fairly common use case that you might want to create yourself.
(A diamond is here because it takes one value, breaks it into two parts, and combines it again again.)
source share