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

Kotlin Tuple.componentX() extensions #779

Open
MelonHell opened this issue Oct 10, 2024 · 1 comment
Open

Kotlin Tuple.componentX() extensions #779

MelonHell opened this issue Oct 10, 2024 · 1 comment

Comments

@MelonHell
Copy link

MelonHell commented Oct 10, 2024

operator fun <U : Any?, V : Any?> Pair<U, V>.component1(): U = first()
operator fun <U : Any?, V : Any?> Pair<U, V>.component2(): V = second()

operator fun <U : Any?, V : Any?, W : Any?> Triplet<U, V, W>.component1(): U = first()
operator fun <U : Any?, V : Any?, W : Any?> Triplet<U, V, W>.component2(): V = second()
operator fun <U : Any?, V : Any?, W : Any?> Triplet<U, V, W>.component3(): W = third()

operator fun <U : Any?, V : Any?, W : Any?, X : Any?> Quartet<U, V, W, X>.component1(): U = first()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?> Quartet<U, V, W, X>.component2(): V = second()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?> Quartet<U, V, W, X>.component3(): W = third()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?> Quartet<U, V, W, X>.component4(): X = fourth()

operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?> Quintet<U, V, W, X, Y>.component1(): U = first()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?> Quintet<U, V, W, X, Y>.component2(): V = second()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?> Quintet<U, V, W, X, Y>.component3(): W = third()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?> Quintet<U, V, W, X, Y>.component4(): X = fourth()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?> Quintet<U, V, W, X, Y>.component5(): Y = fifth()

operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?, Z : Any?> Sextet<U, V, W, X, Y, Z>.component1(): U = first()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?, Z : Any?> Sextet<U, V, W, X, Y, Z>.component2(): V = second()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?, Z : Any?> Sextet<U, V, W, X, Y, Z>.component3(): W = third()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?, Z : Any?> Sextet<U, V, W, X, Y, Z>.component4(): X = fourth()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?, Z : Any?> Sextet<U, V, W, X, Y, Z>.component5(): Y = fifth()
operator fun <U : Any?, V : Any?, W : Any?, X : Any?, Y : Any?, Z : Any?> Sextet<U, V, W, X, Y, Z>.component6(): Z = sixth()
@MelonHell
Copy link
Author

it would also be convenient to have the same for Range

operator fun <N : Number> Range<N>.component1(): N = min()
operator fun <N : Number> Range<N>.component2(): N = max()

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

No branches or pull requests

1 participant