4 ms·
They could have also implemented flat in terms of flatMap: flatMap(x => x) I personally feel flatMap is a much more used method than flat, so if you want to re
by steenreem 7y ago
They could have also implemented flat in terms of flatMap: flatMap(x => x)
I personally feel flatMap is a much more used method than flat, so if you want to remove one, I would remove flat.
- masklinn 7y ago> They could have also implemented flat in terms of flatMap: flatMap(x => x) Flat can flatten any level of nesting (it just defaults to 1), so would be difficult to implement in terms of flatMap.
- contravariant 7y agoYou could reproduce that behaviour of 'flat' by doing something like: function flatten(x, n=1) { return n > 0 ? x.flatmap(y => flatten(y, n-1)) : x; }
- masklinn 7y agoYou could also blow up your stack as there is no requirement whatsoever that javascript implementations be tail-recursive.