Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Kotlin Triple over data class #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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