Skip to content

Instantly share code, notes, and snippets.

@swankjesse

swankjesse/tuples.kt

Last active May 8, 2020
Embed
What would you like to do?
fun main(args: Array<String>) {
println("a" to "b")
println("a" to "b" tre "c")
println("a" to "b" tre "c" fo "d")
println("a" to "b" tre "c" fo "d" fi "e")
println("a" to "b" tre "c" fo "d" fi "e" sik "f")
println("a" to "b" tre "c" fo "d" fi "e" sik "f" seva "g")
}
infix fun <A, B, C> Pair<A, B>.tre(c: C) = Triple(first, second, c)
infix fun <A, B, C, D> Triple<A, B, C>.fo(d: D) = Quad(first, second, third, d)
infix fun <A, B, C, D, E> Quad<A, B, C, D>.fi(e: E) = Jackson(a, b, c, d, e)
infix fun <A, B, C, D, E, F> Jackson<A, B, C, D, E>.sik(f: F) = Rainbow(a, b, c, d, e, f)
infix fun <A, B, C, D, E, F, G> Rainbow<A, B, C, D, E, F>.seva(g: G) = Lucky(a, b, c, d, e, f, g)
data class Quad<out A, out B, out C, out D>(
val a: A,
val b: B,
val c: C,
val d: D
)
data class Jackson<out A, out B, out C, out D, out E>(
val a: A,
val b: B,
val c: C,
val d: D,
val e: E
)
data class Rainbow<out A, out B, out C, out D, out E, out F>(
val a: A,
val b: B,
val c: C,
val d: D,
val e: E,
val f: F
)
data class Lucky<out A, out B, out C, out D, out E, out F, out G>(
val a: A,
val b: B,
val c: C,
val d: D,
val e: E,
val f: F,
val g: G
)
@ultraon

This comment has been minimized.

Copy link

@ultraon ultraon commented Dec 26, 2018

What about suggestion to Kotlin lang? ;-)

@ZacSweers

This comment has been minimized.

Copy link

@ZacSweers ZacSweers commented Nov 12, 2019

Yes officer, this gist right here.

@cgruber

This comment has been minimized.

Copy link

@cgruber cgruber commented May 8, 2020

I regret only that I cannot happily react to the above comment by @ZacSweers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment