Hacker News new | ask | show | jobs
by Dn_Ab 5350 days ago
The higher order monadic join concept cannot be implemented in java but a simpler function in terms of flattening a list of list is easy enough. In a functional language a simple way would be to fold over (++) append.

so in java a simple way would be to initialize an l = arrayList and then do a foreach on each list in the list of the lists and foreach element in each list add it to the arrayList l. Not as elegant, much more how instead of what but 4 noisy lines max.

C# has list.selectMany( _ => _ ) for that.

1 comments

> In a functional language a simple way would be to fold over (++) append.

Though you probably wouldn't want to do use that approach for performance reasons.