Skip to content

Instantly share code, notes, and snippets.

@ummels
Last active August 29, 2015 14:18
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 ummels/eacd9ba58c4ce167ca2d to your computer and use it in GitHub Desktop.
Save ummels/eacd9ba58c4ce167ca2d to your computer and use it in GitHub Desktop.
/** 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