[Docs] Samples for 'step' function
This commit is contained in:
committed by
Space Team
parent
53645bce2b
commit
35b3a9ec82
@@ -961,6 +961,8 @@ public fun CharProgression.reversed(): CharProgression {
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*
|
||||
* @sample samples.ranges.Ranges.stepInt
|
||||
*/
|
||||
public infix fun IntProgression.step(step: Int): IntProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
@@ -969,6 +971,8 @@ public infix fun IntProgression.step(step: Int): IntProgression {
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*
|
||||
* @sample samples.ranges.Ranges.stepLong
|
||||
*/
|
||||
public infix fun LongProgression.step(step: Long): LongProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
@@ -977,6 +981,8 @@ public infix fun LongProgression.step(step: Long): LongProgression {
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*
|
||||
* @sample samples.ranges.Ranges.stepChar
|
||||
*/
|
||||
public infix fun CharProgression.step(step: Int): CharProgression {
|
||||
checkStepIsPositive(step > 0, step)
|
||||
|
||||
@@ -345,6 +345,8 @@ public fun ULongProgression.reversed(): ULongProgression {
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*
|
||||
* @sample samples.ranges.Ranges.stepUInt
|
||||
*/
|
||||
@SinceKotlin("1.5")
|
||||
@WasExperimental(ExperimentalUnsignedTypes::class)
|
||||
@@ -355,6 +357,8 @@ public infix fun UIntProgression.step(step: Int): UIntProgression {
|
||||
|
||||
/**
|
||||
* Returns a progression that goes over the same range with the given step.
|
||||
*
|
||||
* @sample samples.ranges.Ranges.stepULong
|
||||
*/
|
||||
@SinceKotlin("1.5")
|
||||
@WasExperimental(ExperimentalUnsignedTypes::class)
|
||||
|
||||
@@ -52,4 +52,44 @@ class Ranges {
|
||||
assertTrue(3.14f in range)
|
||||
assertFalse(100.1f in range)
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun stepInt() {
|
||||
val ascendingProgression = 1..6 step 2
|
||||
val descendingProgression = 6 downTo 1 step 2
|
||||
assertPrints(ascendingProgression.toList(), "[1, 3, 5]")
|
||||
assertPrints(descendingProgression.toList(), "[6, 4, 2]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun stepUInt() {
|
||||
val ascendingProgression = 1u..6u step 2
|
||||
val descendingProgression = 6u downTo 1u step 2
|
||||
assertPrints(ascendingProgression.toList(), "[1, 3, 5]")
|
||||
assertPrints(descendingProgression.toList(), "[6, 4, 2]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun stepLong() {
|
||||
val ascendingProgression = 1L..6L step 2L
|
||||
val descendingProgression = 6L downTo 1L step 2L
|
||||
assertPrints(ascendingProgression.toList(), "[1, 3, 5]")
|
||||
assertPrints(descendingProgression.toList(), "[6, 4, 2]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun stepULong() {
|
||||
val ascendingProgression = 1UL..6UL step 2L
|
||||
val descendingProgression = 6UL downTo 1UL step 2L
|
||||
assertPrints(ascendingProgression.toList(), "[1, 3, 5]")
|
||||
assertPrints(descendingProgression.toList(), "[6, 4, 2]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun stepChar() {
|
||||
val ascendingProgression = 'a'..'f' step 2
|
||||
val descendingProgression = 'f' downTo 'a' step 2
|
||||
assertPrints(ascendingProgression.toList(), "[a, c, e]")
|
||||
assertPrints(descendingProgression.toList(), "[f, d, b]")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user