Last active
August 29, 2015 14:18
-
-
Save ummels/eacd9ba58c4ce167ca2d to your computer and use it in GitHub Desktop.
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
/** Implicit class for adding `|>` and `tap` operations to `AnyVal`. | |
* | |
* See `http://stackoverflow.com/a/11120847/839131`. | |
*/ | |
implicit class PipeAndTap[A](val x: A) extends AnyVal { | |
/** Applies `f` to the underlying value and returns the result. */ | |
def |>[B](f: A => B) = f(x) | |
/** Applies `f` to the underlying value `x` (presumably with side effects) | |
* and returns `x`. | |
*/ | |
def tap[B](f: A => B): A = { f(x); x } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment