Skip to content

Instantly share code, notes, and snippets.

@loicdescotte
Created July 13, 2018 14:43
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 loicdescotte/0ed778a762fba4e91a81eaa51c8bf442 to your computer and use it in GitHub Desktop.
Save loicdescotte/0ed778a762fba4e91a81eaa51c8bf442 to your computer and use it in GitHub Desktop.
Scala pipe function operator
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