Last active
January 12, 2017 08:45
-
-
Save b-studios/f0904c7b9b4d09164d6aa1e085364f39 to your computer and use it in GitHub Desktop.
F# pipe operator in Scala
This file contains hidden or 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
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