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

commonMain.extensions.ClosedRange.kt Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
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