karelpeeters
12/03/2018, 9:39 AMgroupingBy have any use cases other than eachCount?robin
12/03/2018, 9:42 AMkarelpeeters
12/03/2018, 9:43 AMgroupingBy is lazy vs groupBy which is eager.karelpeeters
12/03/2018, 9:44 AMMap<K,T>.eachCount(): Introbin
12/03/2018, 9:47 AMkarelpeeters
12/03/2018, 9:49 AMGrouping<T,K> is basically a lazy Map<K,List<T>>, right?karelpeeters
12/03/2018, 9:49 AMMap<K,Int> that counts the amounts of `T`s that maps to each K.karelpeeters
12/03/2018, 9:54 AMkarelpeeters
12/03/2018, 9:54 AMtodd.ginsberg
12/03/2018, 2:07 PMkarelpeeters
12/03/2018, 3:31 PMilya.gorbunov
12/03/2018, 7:00 PMFunny that there's noMap<K,T>.eachCount(): Int
So it would return aWouldn't it bethat counts the amounts of `T`s that maps to eachMap<K,Int>.K
1 for each key in the map?robin
12/03/2018, 7:01 PMkarelpeeters
12/03/2018, 7:03 PMilya.gorbunov
12/03/2018, 7:03 PMMap<T, Int>. I don't find that consistent enough with the existing eachCount to name it with the same name.karelpeeters
12/03/2018, 7:05 PMlist.groupBy { f(it) }.eachCount() should return the same thing as list.groupingBy { f(it) }.eachCount().kartikpatodi
12/03/2018, 7:10 PMstring.groupBy { it }.mapValues{it.values.size}
and
string.groupingBy { it }.eachCount()?karelpeeters
12/03/2018, 7:11 PMkartikpatodi
12/03/2018, 7:14 PMlazy concept clearly😅karelpeeters
12/03/2018, 7:18 PM(0..100_000_100).asSequence().filter { it % 2 == 0 }.sum() finishes in 260ms pretty much instantly
(0..100_000_100).filter { it % 2 == 0 }.sum() builds an intermediate list of 100_000_000 elements and that takes 20 seconds.kartikpatodi
12/03/2018, 7:19 PM