Skip to content

Instantly share code, notes, and snippets.

@ryoppy
Created January 4, 2015 14:31
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 ryoppy/f11b34d5a0329276abd8 to your computer and use it in GitHub Desktop.
Save ryoppy/f11b34d5a0329276abd8 to your computer and use it in GitHub Desktop.
implicit class RichFunction1[A, B](val f: A => B) extends AnyVal {
def |>[C](g: B => C) = f andThen g
def <|[C](g: C => A) = f compose g
}
val plus = (_: Int) + 1
val minus = (_: Int) - 1
val suffix = (_: Int) + "!"
val f = plus |> minus |> suffix
println(f(1))
println(f(2))
val g = suffix <| minus <| plus
println(g(1))
println(g(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment