STDLIB: bunch of ranges functions
This commit is contained in:
committed by
vvlevchenko
parent
680cde41fa
commit
34e17e82f4
@@ -0,0 +1,145 @@
|
||||
package kotlin.ranges
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Int.until(to: Byte): IntRange {
|
||||
return this .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Long.until(to: Byte): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Byte.until(to: Byte): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Short.until(to: Byte): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to ['\u0000'] the returned range is empty.
|
||||
*/
|
||||
public infix fun Char.until(to: Char): CharRange {
|
||||
if (to <= '\u0000') return CharRange.EMPTY
|
||||
return this .. (to - 1).toChar()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Int.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this .. (to - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Long.until(to: Int): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Byte.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this.toInt() .. (to - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Int.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Short.until(to: Int): IntRange {
|
||||
if (to <= Int.MIN_VALUE) return IntRange.EMPTY
|
||||
return this.toInt() .. (to - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Int.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Long.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this .. (to - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Byte.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*
|
||||
* If the [to] value is less than or equal to [Long.MIN_VALUE] the returned range is empty.
|
||||
*/
|
||||
public infix fun Short.until(to: Long): LongRange {
|
||||
if (to <= Long.MIN_VALUE) return LongRange.EMPTY
|
||||
return this.toLong() .. (to - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Int.until(to: Short): IntRange {
|
||||
return this .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Long.until(to: Short): LongRange {
|
||||
return this .. (to.toLong() - 1).toLong()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Byte.until(to: Short): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a range from this value up to but excluding the specified [to] value.
|
||||
*/
|
||||
public infix fun Short.until(to: Short): IntRange {
|
||||
return this.toInt() .. (to.toInt() - 1).toInt()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user