Thread
#stdlib
    m

    Marc Knaup

    1 year ago
    Suggestion:
    ClosedRange<T>.mapBounds()
    val range = 1 .. 10
    val shiftedRange = range.mapBounds { it + 10 } // = 11 .. 20
    val characters = "a" .. "z"
    val uppercaseCharacters = characters.mapBounds { it.toUpperCase() } // == "A" .. "Z"
    fun <T : Comparable<T>, R : Comparable<R>> ClosedRange<T>.mapBounds(transform: (T) -> R): ClosedRange<R> =
        transform(start) .. transform(endInclusive)
    
    // plus overloads for primitive ranges
    Note that due to KT-43981 this cannot be properly implemented at the moment for primitive boundary-producing transformations as it would break the generic case: https://youtrack.jetbrains.com/issue/KT-43981
    a

    Astronaut4449

    1 year ago
    How about
    mapUpperBound
    ,
    mapLowerBound
    , and
    mapBounds
    which takes a pair?
    m

    Marc Knaup

    1 year ago
    A pair of what?
    a

    Astronaut4449

    1 year ago
    A pair of ints or chars. Depending on your generic type.
    m

    Marc Knaup

    1 year ago
    I want to map both ends of the range with a single function. No
    Pair
    involved.
    a

    Astronaut4449

    1 year ago
    Ah sorry. My fault
    m

    Marc Knaup

    1 year ago
    No worries, thanks for trying to help 😃