The equivalent of `flatMap` is not `flatten`. Semantically `flatMap` is equivalent to `(comp flatten map)` – hence the name! – but Clojure does offer it as a single function named `mapcat` (”map and catenate”).
With the caveat that `flatten` is recursive and can handle a mix of collections and non-collections, while `mapcat` is non-recursive and every value returned by the mapcatted function must be a collection or nil.
(Identity returns its argument.)
(flatten [1 [2 3] [[4 5 6]]])
> [1 2 3 4 5 6]
(mapcat identity [1 [2 3] [[4 5 6]]])
> IllegalArgumentException Don't know how to create ISeq from: java.lang.Long
(mapcat identity [[1] [2 3] [[4 5 6]]])
> (1 2 3 [4 5 6])
(flatten [nil [1 2 3]])
> (nil 1 2 3)
(mapcat identity [nil [1 2 3]])
> (1 2 3)From this I provisionally conclude that "flatten" being non-recursive is an artifact of Scala confusing things; not an unusual thing in my experience with this language, but this time it seems to have gotten out of hand, instead of being contained within Scala ecosystem.
--
[0] - Even Haskell calls this `concatMap`, see [1].
[1] - https://stackoverflow.com/questions/49843262/where-does-the-...