Tuples.kt
TLDR
This file provides alternative implementations of common Kotlin Pair classes that avoid boxing the primitive types Long
and Int
.
Classes
LongObjectPair
This class is an alternative implementation of Pair<Long, Object>
that avoids boxing the Long
value.
IntObjectPair
This class is an alternative implementation of Pair<Int, Object>
that avoids boxing the Int
value.
LongLongPair
This class is an alternative implementation of Pair<Long, Long>
that avoids boxing both Long
values.
Methods
This file contains three infix extension functions:
Long.to
This function is an infix extension function on Long
, allowing to create a LongObjectPair
by infix notation. It takes an argument of any type (B
) and returns a LongObjectPair
with the Long
value as the first element and the provided argument as the second element.
Int.to
This function is an infix extension function on Int
, allowing to create an IntObjectPair
by infix notation. It takes an argument of any type (B
) and returns an IntObjectPair
with the Int
value as the first element and the provided argument as the second element.
Long.to
This function is an infix extension function on Long
, allowing to create a LongLongPair
by infix notation. It takes a Long
argument and returns a LongLongPair
with the Long
value as both the first and second elements.
package shark.internal.hppc
/** Alternative to Pair<Long, Object> that doesn't box long.*/
internal data class LongObjectPair<out B>(
val first: Long,
val second: B
)
/** Alternative to Pair<Int, Object> that doesn't box int.*/
internal data class IntObjectPair<out B>(
val first: Int,
val second: B
)
/** Alternative to Pair<Long, Long> that doesn't box longs. */
internal data class LongLongPair(
val first: Long,
val second: Long
)
internal infix fun <B> Long.to(that: B): LongObjectPair<B> = LongObjectPair(this, that)
internal infix fun <B> Int.to(that: B): IntObjectPair<B> = IntObjectPair(this, that)
internal infix fun Long.to(that: Long): LongLongPair = LongLongPair(this, that)