add curry

This commit is contained in:
tursom 2021-10-14 09:58:18 +08:00
parent 4666e3a147
commit 03b83bbe17
7 changed files with 4569 additions and 0 deletions

View File

@ -7,6 +7,7 @@ include("ts-core:ts-datastruct")
include("ts-core:ts-pool")
include("ts-core:ts-hash")
include("ts-core:ts-log")
include("ts-core:ts-curry")
include("ts-core:ts-delegation")
include("ts-core:ts-delegation:ts-observer")
include("ts-core:ts-clone")

View File

@ -0,0 +1,14 @@
plugins {
kotlin("jvm")
`maven-publish`
id("ts-gradle")
}
dependencies {
implementation(project(":"))
implementation(project(":ts-core"))
}

View File

@ -0,0 +1,114 @@
package cn.tursom.core.curry
fun <T1, R> curry(action: (a1: T1) -> R) = Curry1(action)
fun <T1, T2, R> curry(action: (a1: T1, a2: T2) -> R) = Curry2 { a1: T1, a2: T2 ->
action(a1, a2)
}
fun <T1, T2, T3, R> curry(action: (a1: T1, a2: T2, a3: T3) -> R) = Curry3 { a1: T1, a2: T2, a3: T3 ->
action(a1, a2, a3)
}
fun <T1, T2, T3, T4, R> curry(action: (T1, T2, T3, T4) -> R) = Curry4 { a1: T1, a2: T2, a3: T3, a4: T4 ->
action(a1, a2, a3, a4)
}
fun <T1, T2, T3, T4, T5, R> curry(action: (T1, T2, T3, T4, T5) -> R) =
Curry5 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5 ->
action(a1, a2, a3, a4, a5)
}
fun <T1, T2, T3, T4, T5, T6, R> curry(action: (T1, T2, T3, T4, T5, T6) -> R) =
Curry6 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6 ->
action(a1, a2, a3, a4, a5, a6)
}
fun <T1, T2, T3, T4, T5, T6, T7, R> curry(action: (T1, T2, T3, T4, T5, T6, T7) -> R) =
Curry7 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7 ->
action(a1, a2, a3, a4, a5, a6, a7)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, R> curry(action: (T1, T2, T3, T4, T5, T6, T7, T8) -> R) =
Curry8 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8 ->
action(a1, a2, a3, a4, a5, a6, a7, a8)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> curry(action: (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R) =
Curry9 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> curry(action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R) =
Curry10 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R
) =
Curry11 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> R
) = Curry12 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) -> R
) = Curry13 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) -> R
) =
Curry14 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13, a14: T14 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) -> R
) = Curry15 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13, a14: T14, a15: T15 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) -> R
) = Curry16 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13, a14: T14, a15: T15, a16: T16 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) -> R
) = Curry17 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13, a14: T14, a15: T15, a16: T16, a17: T17 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) -> R
) = Curry18 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13, a14: T14, a15: T15, a16: T16, a17: T17, a18: T18 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) -> R
) = Curry19 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13, a14: T14, a15: T15, a16: T16, a17: T17, a18: T18, a19: T19 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19)
}
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R> curry(
action: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) -> R
) = Curry20 { a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12,
a13: T13, a14: T14, a15: T15, a16: T16, a17: T17, a18: T18, a19: T19, a20: T20 ->
action(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
}

View File

@ -0,0 +1,234 @@
//package cn.tursom.core.curry
//
//import com.ddbes.kotlin.util.uncheckedCast
//
//operator fun <T1, T2, R> Curry1<T1, Curry1<T2, R>>.invoke(a1: T1, a2: T2): R {
// return if (this is Curry2) {
// uncheckedCast<Curry2<T1, T2, R>>()(a1, a2)
// } else {
// invoke(a1)(a2)
// }
//}
//
//operator fun <T1, T2, T3, R> Curry1<T1, Curry1<T2, Curry1<T3, R>>>.invoke(a1: T1, a2: T2, a3: T3): R {
// return if (this is Curry3) {
// uncheckedCast<Curry3<T1, T2, T3, R>>()(a1, a2, a3)
// } else {
// invoke(a1)(a2)(a3)
// }
//}
//
//operator fun <T1, T2, T3, T4, R> Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, R>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4
//): R {
// return if (this is Curry4) {
// uncheckedCast<Curry4<T1, T2, T3, T4, R>>()(a1, a2, a3, a4)
// } else {
// invoke(a1)(a2)(a3)(a4)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, R> Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, R>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5
//): R {
// return if (this is Curry5) {
// uncheckedCast<Curry5<T1, T2, T3, T4, T5, R>>()(a1, a2, a3, a4, a5)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, R>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6
//): R {
// return if (this is Curry6) {
// uncheckedCast<Curry6<T1, T2, T3, T4, T5, T6, R>>()(a1, a2, a3, a4, a5, a6)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, R>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7
//): R {
// return if (this is Curry7) {
// uncheckedCast<Curry7<T1, T2, T3, T4, T5, T6, T7, R>>()(a1, a2, a3, a4, a5, a6, a7)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, R>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8
//): R {
// return if (this is Curry8) {
// uncheckedCast<Curry8<T1, T2, T3, T4, T5, T6, T7, T8, R>>()(a1, a2, a3, a4, a5, a6, a7, a8)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, R>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9
//): R {
// return if (this is Curry9) {
// uncheckedCast<Curry9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R>>()(a1, a2, a3, a4, a5, a6, a7, a8, a9)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10, R>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10
//): R {
// return if (this is Curry10) {
// uncheckedCast<Curry10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R>>()(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, R>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11
//): R {
// return if (this is Curry11) {
// uncheckedCast<Curry11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, R>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12
//): R {
// return if (this is Curry12) {
// uncheckedCast<Curry12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, R>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13
//): R {
// return if (this is Curry13) {
// uncheckedCast<Curry13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, R>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14
//): R {
// return if (this is Curry14) {
// uncheckedCast<Curry14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, Curry1<T15, R>>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14, a15: T15
//): R {
// return if (this is Curry15) {
// uncheckedCast<Curry15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, Curry1<T15, Curry1<T16, R>>>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14, a15: T15, a16: T16
//): R {
// return if (this is Curry16) {
// uncheckedCast<Curry16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, Curry1<T15, Curry1<T16, Curry1<T17, R>>>>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14, a15: T15, a16: T16, a17: T17
//): R {
// return if (this is Curry17) {
// uncheckedCast<Curry17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, Curry1<T15, Curry1<T16, Curry1<T17, Curry1<T18,
// R>>>>>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14, a15: T15, a16: T16, a17: T17, a18: T18
//): R {
// return if (this is Curry18) {
// uncheckedCast<Curry18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, Curry1<T15, Curry1<T16, Curry1<T17, Curry1<T18, Curry1<T19,
// R>>>>>>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14, a15: T15, a16: T16, a17: T17, a18: T18, a19: T19
//): R {
// return if (this is Curry19) {
// uncheckedCast<Curry19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)
// }
//}
//
//operator fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R>
// Curry1<T1, Curry1<T2, Curry1<T3, Curry1<T4, Curry1<T5, Curry1<T6, Curry1<T7, Curry1<T8, Curry1<T9, Curry1<T10,
// Curry1<T11, Curry1<T12, Curry1<T13, Curry1<T14, Curry1<T15, Curry1<T16, Curry1<T17, Curry1<T18, Curry1<T19,
// Curry1<T20, R>>>>>>>>>>>>>>>>>>>>.invoke(
// a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, a7: T7, a8: T8, a9: T9, a10: T10, a11: T11, a12: T12, a13: T13,
// a14: T14, a15: T15, a16: T16, a17: T17, a18: T18, a19: T19, a20: T20
//): R {
// return if (this is Curry20) {
// uncheckedCast<Curry20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R>>()(
// a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
// } else {
// invoke(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10)(a11)(a12)(a13)(a14)(a15)(a16)(a17)(a18)(a19)(a20)
// }
//}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,136 @@
package com.ddbes.kotlin
import com.ddbes.kotlin.util.removeLastChars
import org.junit.Test
class CurryBuilder {
@Test
fun buildCurryClass() {
(3..20).forEach(::buildCurryClass)
}
@Test
fun buildInvokeMethod() {
(3..20).forEach(::buildInvokeMethod)
}
@Test
fun buildMethodInvoker() {
(4..20).forEach(::buildMethodInvoker)
}
fun args(index: Int) = buildString {
repeat(index) {
append("a${it + 1}, ")
}
removeLastChars(2)
}
fun args(fromIndex: Int, toIndex: Int) = buildString {
(fromIndex..toIndex).forEach {
append("a${it}, ")
}
removeLastChars(2)
}
fun types(index: Int) = buildString {
repeat(index) {
append("T${it + 1}, ")
}
removeLastChars(2)
}
fun types(fromIndex: Int, toIndex: Int) = buildString {
(fromIndex..toIndex).forEach {
append("T${it}, ")
}
removeLastChars(2)
}
fun argsWithType(index: Int) = buildString {
repeat(index) {
append("a${it + 1}: T${it + 1}, ")
}
removeLastChars(2)
}
fun buildCurryClass(index: Int) {
val args = args(index)
val argsWithType = argsWithType(index)
val types = types(index)
val invokeAction = "action$index($args)"
println(buildString {
append("open class Curry$index<$types, R>(\n")
append(" val action$index: ($argsWithType) -> R,\n")
append(") : Curry${index - 1}<${types(index - 1)}, Curry1<T$index, R>>({ ${args(index - 1)} ->\n")
append(" Curry1 { a$index ->\n")
append(" action$index($args)\n")
append(" }\n")
append("}) {\n")
if (index > 2) (1..index - 2).forEach { overrideInvoke ->
append(
" override operator fun invoke(${argsWithType(overrideInvoke)}): Curry${index - overrideInvoke}<${
types(overrideInvoke + 1, index)
}, R> = Curry${index - overrideInvoke} { ${args(overrideInvoke + 1, index)} ->\n"
)
append(" $invokeAction\n")
append(" }\n")
append("\n")
}
append(" open operator fun invoke($argsWithType): R = $invokeAction\n")
append("}\n")
})
}
fun buildCurryMethod(index: Int) {
val args = args(index)
val argsWithType = argsWithType(index)
val types = types(index)
println(buildString {
append("fun <$types, R> curry(action: ($types) -> R) =\n")
append(" Curry$index { $argsWithType ->\n")
append(" action($args)\n")
append(" }\n")
})
}
fun buildInvokeMethod(index: Int) {
val args = args(index)
val argsWithType = argsWithType(index)
val types = types(index)
println(buildString {
append("operator fun <$types, R> ")
repeat(index - 1) {
append("Curry1<T${it + 1}, ")
}
append("Curry1<T$index, R>", ">".repeat(index - 1), ".invoke($argsWithType): R {\n")
append(" return if (this is Curry$index) {\n")
append(" uncheckedCast<Curry$index<$types, R>>()($args)\n")
append(" } else {\n")
append(" invoke")
repeat(index) { an ->
append("(a${an + 1})")
}
append("\n")
append(" }\n")
append("}\n")
})
}
fun buildMethodInvoker(index: Int) {
val args = args(index)
val argsWithType = argsWithType(index)
val types = types(index)
println("operator fun <$types, R> (($types) -> R).invoke() = curry(this)")
(1 until index).forEach { argCount ->
println(
"operator fun <$types, R> (($types) -> R).invoke(${argsWithType(argCount)}) = " +
"curry(this)(${args(argCount)})"
)
}
println()
}
}