Hi all, how fun is kotlin functional?
given a list of items how can you return a list grouped by consecutive items?
[“Apple, Bananas, Bananas, Orange” ] should return [(apple, 1), (bananas, 2), (orange, 1) ]
I know you could use group by , but it does not respect the order
thanks i think its best to have it in the stdlib 🙂
r
Roukanken
02/10/2022, 8:11 AM
what do you need such a function for, anyways?
I've seen a lot of people request it, but I still haven't figured out why...
m
Michael de Kaste
02/10/2022, 8:15 AM
business logic aside, consecutive counts can be used to record a "change" in values. Perhaps for a game or checking the value of an electric signal.
a
Alex
02/10/2022, 12:11 PM
How about converting the list to a map following the order
b
brabo-hi
02/10/2022, 3:08 PM
@Roukanken let say you have a list of items sorted by date like a call history, the logic would be to group consecutive calls and display their counter