Created
October 1, 2019 13:54
-
-
Save happy-bracket/b51afddfc5638554ce1f9676bc583d7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias Either7<A, B, C, D, E, F, G> = Either<A, Either<B, Either<C, Either<D, Either<E, Either<F, G>>>>>> | |
typealias Either6<A, B, C, D, E, F> = Either7<A, B, C, D, E, F, Nothing> | |
typealias Either5<A, B, C, D, E> = Either7<A, B, C, D, E, Nothing, Nothing> | |
typealias Either4<A, B, C, D> = Either7<A, B, C, D, Nothing, Nothing, Nothing> | |
typealias Either3<A, B, C> = Either7<A, B, C, Nothing, Nothing, Nothing, Nothing> | |
fun <A, B, C, D, E, F, G, R> Either7<A, B, C, D, E, F, G>.fold( | |
ifa: (A) -> R, | |
ifb: (B) -> R, | |
ifc: (C) -> R, | |
ifd: (D) -> R, | |
ife: (E) -> R, | |
iff: (F) -> R, | |
ifg: (G) -> R | |
) = | |
fold(ifa, { b -> | |
b.fold(ifb, { c -> | |
c.fold(ifc, { d -> | |
d.fold(ifd, { e -> | |
e.fold(ife, { f -> | |
f.fold(iff, ifg) | |
}) | |
}) | |
}) | |
}) | |
}) | |
fun <A, B, C, D, E, F, R> Either6<A, B, C, D, E, F>.fold( | |
ifa: (A) -> R, | |
ifb: (B) -> R, | |
ifc: (C) -> R, | |
ifd: (D) -> R, | |
ife: (E) -> R, | |
iff: (F) -> R | |
) = fold(ifa, ifb, ifc, ifd, ife, iff, ::self) | |
fun <A, B, C, D, E, R> Either5<A, B, C, D, E>.fold( | |
ifa: (A) -> R, | |
ifb: (B) -> R, | |
ifc: (C) -> R, | |
ifd: (D) -> R, | |
ife: (E) -> R | |
) = fold(ifa, ifb, ifc, ifd, ife, ::self, ::self) | |
fun <A, B, C, D, R> Either4<A, B, C, D>.fold( | |
ifa: (A) -> R, | |
ifb: (B) -> R, | |
ifc: (C) -> R, | |
ifd: (D) -> R | |
) = fold(ifa, ifb, ifc, ifd, ::self, ::self, ::self) | |
fun <A, B, C, R> Either3<A, B, C>.fold( | |
ifa: (A) -> R, | |
ifb: (B) -> R, | |
ifc: (C) -> R | |
) = fold(ifa, ifb, ifc, ::self, ::self, ::self, ::self) | |
fun <A, B, C, D, E, F, G> Either7<A, B, C, D, E, F, G>.foldAny(): Any = | |
fold({ it as Any }, | |
{ it as Any }, | |
{ it as Any }, | |
{ it as Any }, | |
{ it as Any }, | |
{ it as Any }, | |
{ it as Any }) | |
fun <A, B, C, D, E, F, G> A.variant1(): Either7<A, B, C, D, E, F, G> = | |
Either.Left(this) | |
fun <A, B, C, D, E, F, G> B.variant2(): Either7<A, B, C, D, E, F, G> = | |
Either.Right( | |
Either.Left(this)) | |
fun <A, B, C, D, E, F, G> C.variant3(): Either7<A, B, C, D, E, F, G> = | |
Either.Right( | |
Either.Right( | |
Either.Left(this))) | |
fun <A, B, C, D, E, F, G> D.variant4(): Either7<A, B, C, D, E, F, G> = | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Left(this)))) | |
fun <A, B, C, D, E, F, G> E.variant5(): Either7<A, B, C, D, E, F, G> = | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Left(this))))) | |
fun <A, B, C, D, E, F, G> F.variant6(): Either7<A, B, C, D, E, F, G> = | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Left(this)))))) | |
fun <A, B, C, D, E, F, G> G.variant7(): Either7<A, B, C, D, E, F, G> = | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
Either.Right( | |
this)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment