Skip to content

Instantly share code, notes, and snippets.

@b-studios
Last active January 12, 2017 08:45
Show Gist options
  • Save b-studios/f0904c7b9b4d09164d6aa1e085364f39 to your computer and use it in GitHub Desktop.
Save b-studios/f0904c7b9b4d09164d6aa1e085364f39 to your computer and use it in GitHub Desktop.
F# pipe operator in Scala
package object pipe {
implicit class Pipe[T](t: T) {
def |>[S](f: T => S): S = f(t)
}
def filter[T](f: T => Boolean): List[T] => List[T] = _.filter(f)
def map[A, B](f: A => B): List[A] => List[B] = _.map(f)
// Type inference indeed does play along quite well:
val x: Option[Int] = List(1, 2, 3) |>
filter(_ % 2 == 0) |> map(_ + 1) |> (_.head) |> (_ + 1) |>
Some.apply
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment