LoginSignup
13
13

More than 5 years have passed since last update.

最少のタイピングで部分適用を書く

Posted at

scala学習中です。こちらだと部分適用が非常に簡単に書けますね。

def sum(a: Int, b: Int, c: Int) = a + b + c

val a = sum(1, _: Int, 3)
println( a(2) )

swiftでもこのくらい簡単に書けたらいいのに…

と思った瞬間、ふと気が付きました。
よく考えてみるとswiftでも同じくらい簡単に部分適用が書けます。

func sum(a: Int, b: Int, c: Int) -> Int {
    return a + b + c
}

let a = { sum(1, $0, 3) }
println( a(2) )

なぜかswiftリリース以来ずっと気がつかなかったのでメモしておきます。

13
13
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
13
13