Different behavior between List.flatten() and Enum/Stream.flat_map()

Finally, and possibly more importantly, flattening a single level on flat_map is a common choice on many programming languages, making it the expected behavior for many developers.

Examples are JavaScript:

> [[[123]]].flatMap(x => x)
[[123]]

Ruby:

> [[[123]]].flat_map { |x| x }
=> [[123]]
1 Like