Forked from SteveGilham/gist:e9ef541553e09be75994
Last active
August 29, 2015 14:20
-
-
Save alexland/6ff9df0e8cd279deb573 to your computer and use it in GitHub Desktop.
pipe operator implemented 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 operator | |
object FunctionalPipeline { | |
class PipedObject[T] private[Functional] (value:T) | |
{ | |
def |>[R] (f : T => R) = f(this.value) | |
} | |
implicit def toPiped[T] (value:T) = new PipedObject[T](value) | |
} | |
// inspired by a blog post in mkaz.com using this operator in a Sieve of Eratosthenes implementation: | |
(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment