All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.bkahlert.kommons.tuples.kt Maven / Gradle / Ivy

Go to download

Kommons Core is a Kotlin Multiplatform Library that offers shared features for all Kommons modules.

There is a newer version: 2.8.0
Show newest version
package com.bkahlert.kommons

/** Represents a quartet of values. */
public data class Quadruple(
    /** The first value. */
    public val first: A,
    /** The second value. */
    public val second: B,
    /** The third value. */
    public val third: C,
    /** The fourth value. */
    public val fourth: D,
)

/** Represents a quintet of values. */
public data class Quintuple(
    /** The first value. */
    public val first: A,
    /** The second value. */
    public val second: B,
    /** The third value. */
    public val third: C,
    /** The fourth value. */
    public val fourth: D,
    /** The fifth value. */
    public val fifth: E,
)

/** Creates a tuple of type [Triple] from this [Pair] and [that]. */
public infix fun  Pair.too(that: C): Triple =
    Triple(first, second, that)

/** Creates a tuple of type [Quadruple] from `this` [Triple] and [that]. */
public infix fun  Triple.too(that: D): Quadruple =
    Quadruple(first, second, third, that)

/** Creates a tuple of type [Quintuple] from `this` [Quadruple] and [that]. */
public infix fun  Quadruple.too(that: E): Quintuple =
    Quintuple(first, second, third, fourth, that)

/**
 * Returns a pair containing the results of applying the given [transform] function
 * to each element in the original pair.
 */
public fun  Pair.map(transform: (T) -> R): Pair =
    Pair(transform(first), transform(second))

/**
 * Returns a triple containing the results of applying the given [transform] function
 * to each element in the original triple.
 */
public fun  Triple.map(transform: (T) -> R): Triple =
    Triple(transform(first), transform(second), transform(third))

/**
 * Returns a quadruple containing the results of applying the given [transform] function
 * to each element in the original quadruple.
 */
public fun  Quadruple.map(transform: (T) -> R): Quadruple =
    Quadruple(transform(first), transform(second), transform(third), transform(fourth))

/**
 * Returns a quintuple containing the results of applying the given [transform] function
 * to each element in the original quintuple.
 */
public fun  Quintuple.map(transform: (T) -> R): Quintuple =
    Quintuple(transform(first), transform(second), transform(third), transform(fourth), transform(fifth))




© 2015 - 2025 Weber Informatics LLC | Privacy Policy