3

In the Scala community - there is an apparent fascination with the FlatMap function.

Now I understand that FlatMap is significant because it is used for the bind part of a Monad. (and that the Clojure community hasn't dived into Monads yet, with some wonderful exceptions).

Now in the Clojure Community - there is no corresponding cultural idiom, eg "MapCat that S***".

My theory on the difference between the two communities and the reason for this difference is that the concurrency primitives in Clojure lend it towards solving problems on a single machine, in a single instance. (Ie Clojure is good at concurrency). Whereas in the Scala World, with the rise of the Actor model, Scala is a little more focused on solving multi-machine problems. This focus on multi-machine problems has a higher focus on breaking problems down into their parts, and a greater focus on what can be broken down and Scale. (eg Monoids) (Now I realise there is an STM in Scala, and that Actor models, Avout and Cascalog are wonderful exceptions to this - I'm making a generalization)

My question is, why the Scala fascination with flatmap?

(I'm not trying to start a flamewar - I think both communities have benefited from each others existence - I'm trying to understand a cultural behaviour).

2
  • 4
    If you don't want to start a flamewar (or battle of downvotes/closevotes), you might want to clean up your question. Try to make it clearer what you are actually asking, and try to remove any incendiary language. E.g., `“why the Scala emphasis” is better than “why the Scala obsession”.
    – amon
    Dec 3 '13 at 12:09
  • Done - if you can suggest any others that would be helpful.
    – hawkeye
    Dec 3 '13 at 21:23
7

Now I understand that FlatMap is significant because it is used for the bind part of a Monad. (and that the Clojure community hasn't dived into Monads yet, with some wonderful exceptions).

I think that's pretty much the entire explanation. Many Scala idioms and approaches are derived from Haskell, and so it pays a lot of attention to type-safety, monads, etc.

Now in the Clojure Community - there is no corresponding cultural idiom, eg "MapCat that S***".

mapcat only works with collections, unlike flatMap.

This focus on multi-machine problems has a higher focus on breaking problems down into their parts, and a greater focus on what can be broken down and Scale. (eg Monoids) (Now I realise there is an STM in Scala, and that Actor models, Avout and Cascalog are wonderful exceptions to this - I'm making a generalisation)

Better example of this in Clojure core is Reducers.

6
  • Could you elaborate on "mapcat only works with collections, unlike flatMap"?
    – hawkeye
    Dec 4 '13 at 0:36
  • What's to elaborate? mapcat is specifically for collections. It isn't part of a protocol, so can't be made to work on other types. In Scala any monad-like type can define a flatMap method. Dec 4 '13 at 5:52
  • You're implying that mapcat is inferior to flatmap - and I'd like some details on why they're different.
    – hawkeye
    Dec 4 '13 at 8:22
  • No, I am implying mapcat is a specific particular case of flatMap. Dec 4 '13 at 15:08
  • Ok - could you provide a link to explain that further?
    – hawkeye
    Dec 5 '13 at 9:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.