Manuel Pérez Alcolea
08/17/2020, 7:53 PMasSequence()
instead. And something like a direct map
gives you a list. But I would still assume a range object doesn't contain anything, simply because "it makes sense" in my head.
>>> (0..4).asSequence()
res0: kotlin.sequences.Sequence<kotlin.Int> = kotlin.collections.CollectionsKt___CollectionsKt$asSequence$$inlined$Sequence$1@7bafb922
>>> (0..4).map { it * 2 }
res1: kotlin.collections.List<kotlin.Int> = [0, 2, 4, 6, 8]
So what's in an IntRange
before applying anything? (no asSequence()
) for example val myRange = 0..4
Nir
08/17/2020, 8:11 PMNir
08/17/2020, 8:11 PMin
Nir
08/17/2020, 8:12 PMNir
08/17/2020, 8:12 PMNir
08/17/2020, 8:13 PMNir
08/17/2020, 8:13 PMNir
08/17/2020, 8:13 PMNir
08/17/2020, 8:14 PMNir
08/17/2020, 8:14 PMnanodeath
08/17/2020, 8:16 PMfor (i in 1..4)
) may even get compiled away.Manuel Pérez Alcolea
08/17/2020, 8:17 PMbut when you do chain operations on it (via e.g. map) it does things eagerlythanks, this is exactly what I meant. I'm glad I didn't need to give extra information to communicate the idea properly
Nir
08/17/2020, 8:17 PMmap
, are simply generic extension functions. There's one map
for sequences, which is lazy, and one for iterables, which isn't.Nir
08/17/2020, 8:17 PMManuel Pérez Alcolea
08/17/2020, 8:18 PM(e.g.ah yes, I saw that in the bytecode before. Well done compiler, well done. That's why I mentioned) may even get compiled away.for (i in 1..4)
IntRange
specifically