Created
July 13, 2018 14:43
-
-
Save loicdescotte/0ed778a762fba4e91a81eaa51c8bf442 to your computer and use it in GitHub Desktop.
Scala pipe function operator
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
implicit class AnyEx[T](val v: T) extends AnyVal { | |
def |>[U](f: T ⇒ U): U = f(v) | |
} | |
//example | |
def f(l: List[Int]) = l.filter(x => x >1) | |
def g(l: List[Int]) = l.filter(x => x <3) | |
List(1,2,3) |> f |> g //List(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment