5 ms·
>I dislike the fact that Clojure can, in a sense, be written forwards or backwards. If you're referring to the distinction between -> and ->>, it's not about d
by ataggart 14y ago
>I dislike the fact that Clojure can, in a sense, be written forwards or backwards.
If you're referring to the distinction between -> and ->>, it's not about direction preference, but rather that functions that conceptually work on a single subject (e.g., conj, assoc) typically take that subject as its first arg, whereas functions that work on a sequence subject (e.g., map, filter) typically take that subject as its last arg. From that consistency emerges the two different threading macros.
- kenko 14y agoThe parent is almost certainly referring to the distinction between: (-> (initial) a b c d e) and (e (d (c (b (a (initial)))))) I find -> and ->> useful, but the new threading operators kind of silly; they're very easy to implement in terms of -> and ->>, or in terms of higher-order functions, and don't really cover all the use cases one would want---it offends my sense of aesthetics to have them (in their particular implementation) added to the core ns.
- vorg 14y ago(-> (initial) a b c d e) is like "The city on the bay in California" and (e (d (c (b (a (initial)))))) is like "The Californian bay's city". These variations are different thematic structures to language.
- pyrtsa 14y agoIn my view it's exactly the opposite: (-> (california) bay-in city-on) ; "The Californian bay's city" vs. (city-on (bay-in (california))) ; "The city on the bay in California" The former ("->") starts with what's fed into the pipeline, the latter starts with what you get out of it. In addition, "->" avoids the nesting of expressions regardless of the number of steps, which might be useful in some cases. But both styles have their place.