What are the differences between mapcat in Clojure and flatMap in Scala in terms of what they operate on?

后端 未结 4 1183
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 14:13

I understand the equivalent to flatMap in Scala is mapcat in Clojure.

I have an inkling that mapcat in clojure only works with sequences, unli

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 14:50

    They seem very similar and appear to work on the same kind of things. From looking at the documentation and examples I can't see a functional difference.

    mapcat works on sequences, and just about every clojure data type can be a sequence. If you pass something that is not already a seq to mapcat it will call seq on it automatically, so in practice you can pass just about all clojure values to mapcat. If you want to iterate over a tree you would need to call prewalk or postwalk to specify the traversal order.

提交回复
热议问题