Re: Maps, keywords, and functions

2012-12-21 Thread Marko Topolnik
Another common use case: leveraging the thrush operator. (- odd-coll :foo :bar :baz) On Friday, December 21, 2012 12:57:15 AM UTC+1, tbc++ wrote: I use them sometimes in transversing deep maps: (def odd-coll [{:foo {:bar {:baz 42}}} {:foo {:bar {:baz 43}}}]) (def

Re: Maps, keywords, and functions

2012-12-21 Thread travis vachon
Having both options available also allows you to make NullPointerException-averse decisions as appropriate. That is, in this function: (defn foo [a-map] (a-map :foo)) I'm potentially exposed to an NPE if the given map is nil. By rewriting it: (defn foo [a-map] (:foo a-map)) I avoid this

Maps, keywords, and functions

2012-12-20 Thread Jonathon McKitrick
I thought it was pretty interesting to treat maps as functions, and even more intrigued at treating keywords as functions as well. What does this gain from a language design perspective, that you cannot get with (get map keyword) or ever (map keyword)? Why the additional option of (keyword

Re: Maps, keywords, and functions

2012-12-20 Thread Dave Ray
You can avoid superfluous anonymous functions. For example, this: (map #(get % :id) my-sequence) vs this: (map :id my-sequence) Cheers, Dave On Thu, Dec 20, 2012 at 3:13 PM, Jonathon McKitrick jmckitr...@gmail.com wrote: I thought it was pretty interesting to treat maps as functions,

Re: Maps, keywords, and functions

2012-12-20 Thread Timothy Baldridge
I use them sometimes in transversing deep maps: (def odd-coll [{:foo {:bar {:baz 42}}} {:foo {:bar {:baz 43}}}]) (def find-it (comp :baz :bar :foo)) (map find-it odd-coll) ; [42 43] On Thu, Dec 20, 2012 at 4:41 PM, Dave Ray dave...@gmail.com wrote: You can avoid