Hexa
06/10/2019, 8:53 AMsequence
vs when to use streams
? i know sequence is for processing large collection of data, but is there any reason why can't I use it to process small amount of data?gildor
06/10/2019, 8:55 AMgildor
06/10/2019, 8:56 AMwhy can’t I use it to process small amount of dataBecause eager collection operators will be faster for small collections
gildor
06/10/2019, 9:10 AMgildor
06/10/2019, 9:11 AMkarelpeeters
06/10/2019, 9:44 AMSequence
operations would be compiled to normal for loops as well.gildor
06/10/2019, 9:46 AMgildor
06/10/2019, 9:46 AMkarelpeeters
06/10/2019, 9:50 AMval res = list.filter(::f).filter(::g).flatMap(::h).toList()
should be compilable to
val res = mutableListOf()
for (e in list) {
if (!f(e)) continue
if (!g(e)) continue
for (n in h(e))
res += n
}
Or are there exceptions I'm not aware of?gildor
06/10/2019, 9:51 AMkarelpeeters
06/10/2019, 9:52 AMgildor
06/10/2019, 9:52 AMkarelpeeters
06/10/2019, 9:53 AMgildor
06/10/2019, 9:53 AMgildor
06/10/2019, 9:53 AMkarelpeeters
06/10/2019, 9:54 AMfilter
with &&
but that breaks down when you have something like filter.map.filter
. Then I just start abusing mapNotNull
, it's an unfortunate situation.karelpeeters
06/10/2019, 9:55 AMkarelpeeters
06/10/2019, 9:55 AMgildor
06/10/2019, 10:01 AMkarelpeeters
06/10/2019, 10:02 AM