fuookami.ospf.kotlin.utils.functional.Variant.kt Maven / Gradle / Ivy
package fuookami.ospf.kotlin.utils.functional
import kotlin.reflect.*
import kotlin.collections.*
import fuookami.ospf.kotlin.utils.concept.*
sealed class Variant2() {
data class V1(val value: T1) : Variant2() {}
data class V2(val value: T2) : Variant2() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant2Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant2Matcher(this).if2(callBack);
}
data class Variant2Matcher(private val value: Variant2) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant2Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant2Matcher {
callBack2 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant2.V1 -> {
callBack1(value.value)
}
is Variant2.V2 -> {
callBack2(value.value)
}
}
}
sealed class Variant3() {
data class V1(val value: T1) : Variant3() {}
data class V2(val value: T2) : Variant3() {}
data class V3(val value: T3) : Variant3() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant3Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant3Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant3Matcher(this).if3(callBack);
}
data class Variant3Matcher(private val value: Variant3) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant3Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant3Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant3Matcher {
callBack3 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant3.V1 -> {
callBack1(value.value)
}
is Variant3.V2 -> {
callBack2(value.value)
}
is Variant3.V3 -> {
callBack3(value.value)
}
}
}
sealed class Variant4() {
data class V1(val value: T1) : Variant4() {}
data class V2(val value: T2) : Variant4() {}
data class V3(val value: T3) : Variant4() {}
data class V4(val value: T4) : Variant4() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant4Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant4Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant4Matcher(this).if3(callBack);
val is4 get() = this is V4;
val v4
get() = when (this) {
is V4 -> {
this.value
}
else -> {
null
}
}
fun if4(callBack: (T4) -> Ret) = Variant4Matcher(this).if4(callBack);
}
data class Variant4Matcher(private val value: Variant4) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
private lateinit var callBack4: (T4) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant4Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant4Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant4Matcher {
callBack3 = callBack;
return this;
}
fun if4(callBack: (T4) -> Ret): Variant4Matcher {
callBack4 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant4.V1 -> {
callBack1(value.value)
}
is Variant4.V2 -> {
callBack2(value.value)
}
is Variant4.V3 -> {
callBack3(value.value)
}
is Variant4.V4 -> {
callBack4(value.value)
}
}
}
sealed class Variant5() {
data class V1(val value: T1) : Variant5() {}
data class V2(val value: T2) : Variant5() {}
data class V3(val value: T3) : Variant5() {}
data class V4(val value: T4) : Variant5() {}
data class V5(val value: T5) : Variant5() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant5Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant5Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant5Matcher(this).if3(callBack);
val is4 get() = this is V4;
val v4
get() = when (this) {
is V4 -> {
this.value
}
else -> {
null
}
}
fun if4(callBack: (T4) -> Ret) = Variant5Matcher(this).if4(callBack);
val is5 get() = this is V5;
val v5
get() = when (this) {
is V5 -> {
this.value
}
else -> {
null
}
}
fun if5(callBack: (T5) -> Ret) = Variant5Matcher(this).if5(callBack);
}
data class Variant5Matcher(private val value: Variant5) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
private lateinit var callBack4: (T4) -> Ret;
private lateinit var callBack5: (T5) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant5Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant5Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant5Matcher {
callBack3 = callBack;
return this;
}
fun if4(callBack: (T4) -> Ret): Variant5Matcher {
callBack4 = callBack;
return this;
}
fun if5(callBack: (T5) -> Ret): Variant5Matcher {
callBack5 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant5.V1 -> {
callBack1(value.value)
}
is Variant5.V2 -> {
callBack2(value.value)
}
is Variant5.V3 -> {
callBack3(value.value)
}
is Variant5.V4 -> {
callBack4(value.value)
}
is Variant5.V5 -> {
callBack5(value.value)
}
}
}
sealed class Variant6() {
data class V1(val value: T1) : Variant6() {}
data class V2(val value: T2) : Variant6() {}
data class V3(val value: T3) : Variant6() {}
data class V4(val value: T4) : Variant6() {}
data class V5(val value: T5) : Variant6() {}
data class V6(val value: T6) : Variant6() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant6Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant6Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant6Matcher(this).if3(callBack);
val is4 get() = this is V4;
val v4
get() = when (this) {
is V4 -> {
this.value
}
else -> {
null
}
}
fun if4(callBack: (T4) -> Ret) = Variant6Matcher(this).if4(callBack);
val is5 get() = this is V5;
val v5
get() = when (this) {
is V5 -> {
this.value
}
else -> {
null
}
}
fun if5(callBack: (T5) -> Ret) = Variant6Matcher(this).if5(callBack);
val is6 get() = this is V6;
val v6
get() = when (this) {
is V6 -> {
this.value
}
else -> {
null
}
}
fun if6(callBack: (T6) -> Ret) = Variant6Matcher(this).if6(callBack);
}
data class Variant6Matcher(private val value: Variant6) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
private lateinit var callBack4: (T4) -> Ret;
private lateinit var callBack5: (T5) -> Ret;
private lateinit var callBack6: (T6) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant6Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant6Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant6Matcher {
callBack3 = callBack;
return this;
}
fun if4(callBack: (T4) -> Ret): Variant6Matcher {
callBack4 = callBack;
return this;
}
fun if5(callBack: (T5) -> Ret): Variant6Matcher {
callBack5 = callBack;
return this;
}
fun if6(callBack: (T6) -> Ret): Variant6Matcher {
callBack6 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant6.V1 -> {
callBack1(value.value)
}
is Variant6.V2 -> {
callBack2(value.value)
}
is Variant6.V3 -> {
callBack3(value.value)
}
is Variant6.V4 -> {
callBack4(value.value)
}
is Variant6.V5 -> {
callBack5(value.value)
}
is Variant6.V6 -> {
callBack6(value.value)
}
}
}
sealed class Variant7() {
data class V1(val value: T1) : Variant7() {}
data class V2(val value: T2) : Variant7() {}
data class V3(val value: T3) : Variant7() {}
data class V4(val value: T4) : Variant7() {}
data class V5(val value: T5) : Variant7() {}
data class V6(val value: T6) : Variant7() {}
data class V7(val value: T7) : Variant7() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant7Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant7Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant7Matcher(this).if3(callBack);
val is4 get() = this is V4;
val v4
get() = when (this) {
is V4 -> {
this.value
}
else -> {
null
}
}
fun if4(callBack: (T4) -> Ret) = Variant7Matcher(this).if4(callBack);
val is5 get() = this is V5;
val v5
get() = when (this) {
is V5 -> {
this.value
}
else -> {
null
}
}
fun if5(callBack: (T5) -> Ret) = Variant7Matcher(this).if5(callBack);
val is6 get() = this is V6;
val v6
get() = when (this) {
is V6 -> {
this.value
}
else -> {
null
}
}
fun if6(callBack: (T6) -> Ret) = Variant7Matcher(this).if6(callBack);
val is7 get() = this is V7;
val v7
get() = when (this) {
is V7 -> {
this.value
}
else -> {
null
}
}
fun if7(callBack: (T7) -> Ret) = Variant7Matcher(this).if7(callBack);
}
data class Variant7Matcher(private val value: Variant7) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
private lateinit var callBack4: (T4) -> Ret;
private lateinit var callBack5: (T5) -> Ret;
private lateinit var callBack6: (T6) -> Ret;
private lateinit var callBack7: (T7) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant7Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant7Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant7Matcher {
callBack3 = callBack;
return this;
}
fun if4(callBack: (T4) -> Ret): Variant7Matcher {
callBack4 = callBack;
return this;
}
fun if5(callBack: (T5) -> Ret): Variant7Matcher {
callBack5 = callBack;
return this;
}
fun if6(callBack: (T6) -> Ret): Variant7Matcher {
callBack6 = callBack;
return this;
}
fun if7(callBack: (T7) -> Ret): Variant7Matcher {
callBack7 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant7.V1 -> {
callBack1(value.value)
}
is Variant7.V2 -> {
callBack2(value.value)
}
is Variant7.V3 -> {
callBack3(value.value)
}
is Variant7.V4 -> {
callBack4(value.value)
}
is Variant7.V5 -> {
callBack5(value.value)
}
is Variant7.V6 -> {
callBack6(value.value)
}
is Variant7.V7 -> {
callBack7(value.value)
}
}
}
sealed class Variant8() {
data class V1(val value: T1) : Variant8() {}
data class V2(val value: T2) : Variant8() {}
data class V3(val value: T3) : Variant8() {}
data class V4(val value: T4) : Variant8() {}
data class V5(val value: T5) : Variant8() {}
data class V6(val value: T6) : Variant8() {}
data class V7(val value: T7) : Variant8() {}
data class V8(val value: T8) : Variant8() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant8Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant8Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant8Matcher(this).if3(callBack);
val is4 get() = this is V4;
val v4
get() = when (this) {
is V4 -> {
this.value
}
else -> {
null
}
}
fun if4(callBack: (T4) -> Ret) = Variant8Matcher(this).if4(callBack);
val is5 get() = this is V5;
val v5
get() = when (this) {
is V5 -> {
this.value
}
else -> {
null
}
}
fun if5(callBack: (T5) -> Ret) = Variant8Matcher(this).if5(callBack);
val is6 get() = this is V6;
val v6
get() = when (this) {
is V6 -> {
this.value
}
else -> {
null
}
}
fun if6(callBack: (T6) -> Ret) = Variant8Matcher(this).if6(callBack);
val is7 get() = this is V7;
val v7
get() = when (this) {
is V7 -> {
this.value
}
else -> {
null
}
}
fun if7(callBack: (T7) -> Ret) = Variant8Matcher(this).if7(callBack);
val is8 get() = this is V8;
val v8
get() = when (this) {
is V8 -> {
this.value
}
else -> {
null
}
}
fun if8(callBack: (T8) -> Ret) = Variant8Matcher(this).if8(callBack);
}
data class Variant8Matcher(private val value: Variant8) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
private lateinit var callBack4: (T4) -> Ret;
private lateinit var callBack5: (T5) -> Ret;
private lateinit var callBack6: (T6) -> Ret;
private lateinit var callBack7: (T7) -> Ret;
private lateinit var callBack8: (T8) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant8Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant8Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant8Matcher {
callBack3 = callBack;
return this;
}
fun if4(callBack: (T4) -> Ret): Variant8Matcher {
callBack4 = callBack;
return this;
}
fun if5(callBack: (T5) -> Ret): Variant8Matcher {
callBack5 = callBack;
return this;
}
fun if6(callBack: (T6) -> Ret): Variant8Matcher {
callBack6 = callBack;
return this;
}
fun if7(callBack: (T7) -> Ret): Variant8Matcher {
callBack7 = callBack;
return this;
}
fun if8(callBack: (T8) -> Ret): Variant8Matcher {
callBack8 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant8.V1 -> {
callBack1(value.value)
}
is Variant8.V2 -> {
callBack2(value.value)
}
is Variant8.V3 -> {
callBack3(value.value)
}
is Variant8.V4 -> {
callBack4(value.value)
}
is Variant8.V5 -> {
callBack5(value.value)
}
is Variant8.V6 -> {
callBack6(value.value)
}
is Variant8.V7 -> {
callBack7(value.value)
}
is Variant8.V8 -> {
callBack8(value.value)
}
}
}
sealed class Variant9() {
data class V1(val value: T1) : Variant9() {}
data class V2(val value: T2) : Variant9() {}
data class V3(val value: T3) : Variant9() {}
data class V4(val value: T4) : Variant9() {}
data class V5(val value: T5) : Variant9() {}
data class V6(val value: T6) : Variant9() {}
data class V7(val value: T7) : Variant9() {}
data class V8(val value: T8) : Variant9() {}
data class V9(val value: T9) : Variant9() {}
val is1 get() = this is V1;
val v1
get() = when (this) {
is V1 -> {
this.value
}
else -> {
null
}
}
fun if1(callBack: (T1) -> Ret) = Variant9Matcher(this).if1(callBack);
val is2 get() = this is V2;
val v2
get() = when (this) {
is V2 -> {
this.value
}
else -> {
null
}
}
fun if2(callBack: (T2) -> Ret) = Variant9Matcher(this).if2(callBack);
val is3 get() = this is V3;
val v3
get() = when (this) {
is V3 -> {
this.value
}
else -> {
null
}
}
fun if3(callBack: (T3) -> Ret) = Variant9Matcher(this).if3(callBack);
val is4 get() = this is V4;
val v4
get() = when (this) {
is V4 -> {
this.value
}
else -> {
null
}
}
fun if4(callBack: (T4) -> Ret) = Variant9Matcher(this).if4(callBack);
val is5 get() = this is V5;
val v5
get() = when (this) {
is V5 -> {
this.value
}
else -> {
null
}
}
fun if5(callBack: (T5) -> Ret) = Variant9Matcher(this).if5(callBack);
val is6 get() = this is V6;
val v6
get() = when (this) {
is V6 -> {
this.value
}
else -> {
null
}
}
fun if6(callBack: (T6) -> Ret) = Variant9Matcher(this).if6(callBack);
val is7 get() = this is V7;
val v7
get() = when (this) {
is V7 -> {
this.value
}
else -> {
null
}
}
fun if7(callBack: (T7) -> Ret) = Variant9Matcher(this).if7(callBack);
val is8 get() = this is V8;
val v8
get() = when (this) {
is V8 -> {
this.value
}
else -> {
null
}
}
fun if8(callBack: (T8) -> Ret) = Variant9Matcher(this).if8(callBack);
val is9 get() = this is V9;
val v9
get() = when (this) {
is V9 -> {
this.value
}
else -> {
null
}
}
fun if9(callBack: (T9) -> Ret) = Variant9Matcher(this).if9(callBack);
}
data class Variant9Matcher(private val value: Variant9) {
private lateinit var callBack1: (T1) -> Ret;
private lateinit var callBack2: (T2) -> Ret;
private lateinit var callBack3: (T3) -> Ret;
private lateinit var callBack4: (T4) -> Ret;
private lateinit var callBack5: (T5) -> Ret;
private lateinit var callBack6: (T6) -> Ret;
private lateinit var callBack7: (T7) -> Ret;
private lateinit var callBack8: (T8) -> Ret;
private lateinit var callBack9: (T9) -> Ret;
fun if1(callBack: (T1) -> Ret): Variant9Matcher {
callBack1 = callBack;
return this;
}
fun if2(callBack: (T2) -> Ret): Variant9Matcher {
callBack2 = callBack;
return this;
}
fun if3(callBack: (T3) -> Ret): Variant9Matcher {
callBack3 = callBack;
return this;
}
fun if4(callBack: (T4) -> Ret): Variant9Matcher {
callBack4 = callBack;
return this;
}
fun if5(callBack: (T5) -> Ret): Variant9Matcher {
callBack5 = callBack;
return this;
}
fun if6(callBack: (T6) -> Ret): Variant9Matcher {
callBack6 = callBack;
return this;
}
fun if7(callBack: (T7) -> Ret): Variant9Matcher {
callBack7 = callBack;
return this;
}
fun if8(callBack: (T8) -> Ret): Variant9Matcher {
callBack8 = callBack;
return this;
}
fun if9(callBack: (T9) -> Ret): Variant9Matcher {
callBack9 = callBack;
return this;
}
@Throws(NullPointerException::class)
operator fun invoke() = when (value) {
is Variant9.V1 -> {
callBack1(value.value)
}
is Variant9.V2 -> {
callBack2(value.value)
}
is Variant9.V3 -> {
callBack3(value.value)
}
is Variant9.V4 -> {
callBack4(value.value)
}
is Variant9.V5 -> {
callBack5(value.value)
}
is Variant9.V6 -> {
callBack6(value.value)
}
is Variant9.V7 -> {
callBack7(value.value)
}
is Variant9.V8 -> {
callBack8(value.value)
}
is Variant9.V9 -> {
callBack9(value.value)
}
}
}
sealed class Variant10() {
data class V1(val value: T1) :
Variant10() {}
data class V2(val value: T2) :
Variant10() {}
data class V3(val value: T3) :
Variant10() {}
data class V4