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

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

There is a newer version: 0.14.0
Show newest version
package io.fluidsonic.stdlib

import kotlin.jvm.*
import kotlin.math.*


public operator fun IntRange.component1(): Int =
	first


public operator fun IntRange.component2(): Int =
	last


public fun IntRange.flipped(): IntRange =
	last .. first


public fun > IntRange.mapBounds(transform: (Int) -> R): ClosedRange =
	transform(first) .. transform(last)


@JvmName("mapBoundsToDouble")
public fun IntRange.mapBounds(transform: (Int) -> Double): ClosedFloatingPointRange =
	transform(first) .. transform(last)


@JvmName("mapBoundsToFloat")
public fun IntRange.mapBounds(transform: (Int) -> Float): ClosedFloatingPointRange =
	transform(first) .. transform(last)


public fun IntRange.mapBounds(transform: (Int) -> Int): IntRange =
	transform(first) .. transform(last)


public fun IntRange.mapBounds(transform: (Int) -> Long): LongRange =
	transform(first) .. transform(last)


public fun IntRange.mapBounds(transform: (Int) -> UInt): UIntRange =
	transform(first) .. transform(last)


public fun IntRange.mapBounds(transform: (Int) -> ULong): ULongRange =
	transform(first) .. transform(last)


public fun IntRange.intersection(other: IntRange): HalfOpenIntRange? =
	overlaps(other).thenTake { max(first, other.first) rangeToExcluding min(last, other.last) }


public fun IntRange.overlaps(other: IntRange): Boolean =
	contains(other.first) || other.contains(first)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy