commonMain.extensions.ClosedRange.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluid-stdlib-tvosx64 Show documentation
Show all versions of fluid-stdlib-tvosx64 Show documentation
Potentially useful Kotlin standard library additions
package io.fluidsonic.stdlib
import kotlin.jvm.*
public operator fun > ClosedRange.component1(): Bound =
start
public operator fun > ClosedRange.component2(): Bound =
endInclusive
public fun > ClosedRange.flipped(): ClosedRange =
endInclusive .. start
public fun , R : Comparable> ClosedRange.mapBounds(transform: (Bound) -> R): ClosedRange =
transform(start) .. transform(endInclusive)
@JvmName("mapBoundsToDouble")
public fun > ClosedRange.mapBounds(transform: (Bound) -> Double): ClosedFloatingPointRange =
transform(start) .. transform(endInclusive)
@JvmName("mapBoundsToFloat")
public fun > ClosedRange.mapBounds(transform: (Bound) -> Float): ClosedFloatingPointRange =
transform(start) .. transform(endInclusive)
public fun > ClosedRange.mapBounds(transform: (Bound) -> Int): IntRange =
transform(start) .. transform(endInclusive)
public fun > ClosedRange.mapBounds(transform: (Bound) -> Long): LongRange =
transform(start) .. transform(endInclusive)
public fun > ClosedRange.mapBounds(transform: (Bound) -> UInt): UIntRange =
transform(start) .. transform(endInclusive)
public fun > ClosedRange.mapBounds(transform: (Bound) -> ULong): ULongRange =
transform(start) .. transform(endInclusive)
public fun > ClosedRange.intersection(other: ClosedRange): HalfOpenRange? =
overlaps(other).thenTake { maxOf(start, other.start) rangeToExcluding minOf(endInclusive, other.endInclusive) }
public fun > ClosedRange.overlaps(other: ClosedRange): Boolean =
contains(other.start) || other.contains(start)
public fun > ClosedRange.toSequence(next: (Bound) -> Bound?): Sequence =
when {
isEmpty() -> emptySequence()
else -> generateSequence(start) { start ->
next(start)?.takeIf { value -> contains(value) }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy