I'm looking for something like
val allInts = (1..).asSequence()
so I could, for example
allInts.take(5)
JB's answer is good but you could also go with
generateSequence(1, Int::inc)
if you're into the whole brevity thing.
If you need an infinite sequence you should use the new sequence
function:
val sequence = sequence {
while (true) {
yield(someValue())
}
}
Previous answer
Use Int.MAX_VALUE
as the upper bound. You cannot have an integer greater than Int.MAX_VALUE
.
val allInts = (1..Int.MAX_VALUE).asSequence()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With