Hi all, how fun is kotlin functional? given a list...
# getting-started
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
there is currently no stdlib function for grouping consecutive items https://kotlinlang.slack.com/archives/C0922A726/p1629199729456400
there is an issue discussing one: https://youtrack.jetbrains.com/issue/KT-8280 as well as some possible implementation in the thread I linked
🙏 1
thanks i think its best to have it in the stdlib 🙂
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...
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.
How about converting the list to a map following the order
@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