Skip to content

Conversation

@russellbanks
Copy link
Contributor

In Kotlin, a Tuple is called a Triple. There's no need for a custom data class here. Also, the use of semicolons here seems to be a typo.

Before:

// Kotlin doesn't have tuples, use data classes
data class GasPrices(val a: Double, val b: Double, val c: Double)

fun getGasPrices() = GasPrices(3.59, 3.69, 3.79)

val prices = getGasPrices();

val (a, b, c) = getGasPrices();

After:

fun getGasPrices() = Triple(3.59, 3.69, 3.79)

val prices = getGasPrices()

val (a, b, c) = getGasPrices()

@ttu
Copy link
Owner

ttu commented Oct 1, 2023

Thanks! We could add more Tuple examples, that utilize Kotlin's predefined classes. 1 example could have a tuple with 2 elements (Pair), 1 with 3 elements (Triple) and last with 4(+) elements (data class). Would you like to make Kotlin changes to this PR and I can make C# changes to another PR?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants