Stream: beginners

Topic: List.flatten or List.flatMap


view this post on Zulip Scally (Dec 09 2024 at 17:05):

Am I mistaken or do these functions not exist? How would I go about doing things like that? Do I actually need to implement them myself?

view this post on Zulip Kilian Vounckx (Dec 09 2024 at 17:08):

I think you are looking for joinMap

view this post on Zulip Kilian Vounckx (Dec 09 2024 at 17:08):

And join instead of flatten

view this post on Zulip Scally (Dec 09 2024 at 17:12):

Ah cool, thanks. What about something like joinMapWithIndex?

view this post on Zulip Kilian Vounckx (Dec 09 2024 at 17:14):

As far as I know, it doesn't exists. I use mapWithIndex followed by join in that case. Slightly less performant, but it works

view this post on Zulip Kilian Vounckx (Dec 09 2024 at 17:15):

If you really want the full performance, you'd need to use walk(WithIndex) and allocate the buffer manually up front with List.withCapacity

view this post on Zulip Anthony Bullard (Dec 09 2024 at 17:57):

If you have fold(walk) you can build anything as my old CTO once told me


Last updated: Jul 06 2025 at 12:14 UTC