MarioAriasC / funKTionale

Functional constructs for Kotlin
915 stars 71 forks source link

Alternative currying #5

Closed sirikid closed 8 years ago

sirikid commented 8 years ago
operator fun <P1, P2, R> Function2<P1, P2, R>.invoke(p1: P1) = 
  { p2: P2 -> this(p1, p2) }

operator fun <P1, P2, P3, R> Function3<P1, P2, P3, R>.invoke(p1: P1) = 
  { p2: P2, p3: P3 -> this(p1, p2, p3) }

operator fun <P1, P2, P3, P4, R> Function4<P1, P2, P3, P4, R>.invoke(p1: P1) = 
  { p2: P2, p3: P3, p4: P4 -> this(p1, p2, p3, p4) }

val foo: (Int, Int, Int) -> Int = { a, b, c -> a + b + c }

fun bar(a: Int, b: Int, c: Int) = a + b + c

fun main(args: Array<String>) {
    foo(1, 2, 3)
    foo(1)(2)(3)

    bar(1, 2, 3)
    (::bar)(1)(2)(3)
}