1. A simple histogram of elements given a list of...
# advent-of-code
n
1. A simple histogram of elements given a list of stuff. I end up doing this usually
Copy code
some_stuff.groupBy { it }.mapValues { it.value.size }
Which works but feels a bit silly from a couple of angles
e
this was discussed in today's thread:
some_stuff.groupingBy { it }.eachCount()
🙏 1
n
yeah, I'm aware of groupingBy as well, will be a bit faster I guess
I'll probably add my own extension function then
m
I usually find it silly when I have to write
{ it }
. In this case a small wrapper function (e.g.
grouped()
) would be nice. It’s just much more readable in particular when in a nested lambda (e.g. flatMap)
đź‘Ť 2
l
I like the syntax with Arrow's
identity
fonction:
groupingBy(::identity)