LoginSignup
0
1

More than 5 years have passed since last update.

関数合成を短く

Posted at
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))

記号これじゃないほうがいいな

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1