Skip to content

Instantly share code, notes, and snippets.

@kobakei
Last active March 17, 2018 12:54
Show Gist options
  • Save kobakei/3cfe00f0ee2d914c8284a59c47d19717 to your computer and use it in GitHub Desktop.
Save kobakei/3cfe00f0ee2d914c8284a59c47d19717 to your computer and use it in GitHub Desktop.
Tuple in Kotlin
import java.io.Serializable
public data class Tuple4<out A, out B, out C, out D>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth)"
}
public data class Tuple5<out A, out B, out C, out D, out E>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D,
public val fifth: E
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth, $fifth)"
}
public data class Tuple6<out A, out B, out C, out D, out E, out F>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D,
public val fifth: E,
public val sixth: F
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth, $fifth, $sixth)"
}
public data class Tuple7<out A, out B, out C, out D, out E, out F, out G>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D,
public val fifth: E,
public val sixth: F,
public val seventh: G
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth, $fifth, $sixth, $seventh)"
}
public data class Tuple8<out A, out B, out C, out D, out E, out F, out G, out H>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D,
public val fifth: E,
public val sixth: F,
public val seventh: G,
public val eighth: H
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eighth)"
}
public data class Tuple9<out A, out B, out C, out D, out E, out F, out G, out H, out I>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D,
public val fifth: E,
public val sixth: F,
public val seventh: G,
public val eighth: H,
public val ninth: I
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eighth, $ninth)"
}
public data class Tuple10<out A, out B, out C, out D, out E, out F, out G, out H, out I, out J>(
public val first: A,
public val second: B,
public val third: C,
public val fourth: D,
public val fifth: E,
public val sixth: F,
public val seventh: G,
public val eighth: H,
public val ninth: I,
public val tenth: J
) : Serializable {
public override fun toString(): String = "($first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eighth, $ninth, $tenth)"
}
public fun <T> Tuple4<T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth)
public fun <T> Tuple5<T, T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth, fifth)
public fun <T> Tuple6<T, T, T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth, fifth, sixth)
public fun <T> Tuple7<T, T, T, T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth, fifth, sixth, seventh)
public fun <T> Tuple8<T, T, T, T, T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth, fifth, sixth, seventh, eighth)
public fun <T> Tuple9<T, T, T, T, T, T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth)
public fun <T> Tuple10<T, T, T, T, T, T, T, T, T, T>.toList(): List<T> = listOf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment