rook
10/05/2018, 2:26 PMtoList()
it appears to just make an empty list. Am I doing something wrong?
someList.asSequence()
.also { println(it.count()) } // 11
.filter { thing -> !thing.bool }
.also { println(it.count()) } // 11
.take(CONST_INT)
.map { thing ->
thing.apply {
thing.prop = "newVal"
}
}
.also { println(it.count()) } // 11
.toList()
.also { println(it.count()) } // 0
Andreas Sinz
10/05/2018, 2:40 PMtoList
?Jonathan
10/05/2018, 2:46 PMclass Thing {
val bool get() = false
var prop = "oldVal"
}
const val CONST_INT = 11
val someList = (1..11).map { Thing() }
The snippet you shared prints:
11
11
11
11
Jonathan
10/05/2018, 2:46 PMrook
10/05/2018, 3:05 PMrook
10/05/2018, 3:06 PMtoList()
is called, so it appears to have everything up until I call it, and then filters out everything?Andreas Sinz
10/05/2018, 3:15 PMcount()
iterates over the whole sequence and all operationsAndreas Sinz
10/05/2018, 3:16 PMrook
10/05/2018, 3:16 PMrook
10/05/2018, 5:25 PMmap
mutation outside the sequence evaluation. I’m really unclear on why that fixes it, but the map
mutation does affect the filter
case in my implementation. I can’t reproduce it in a sterile environment though, and I can’t figure out what property of sequence would cause it to re-evaluate everything that way