1 Feb 2009 03:55
Re: meaning of coll
Jason Wolfe <jawolfe <at> berkeley.edu>
2009-02-01 02:55:58 GMT
2009-02-01 02:55:58 GMT
On Jan 31, 6:42 pm, Mark Volkmann <r.mark.volkm... <at> gmail.com> wrote:
> When a function parameter is named "coll", does that generally mean it
> can be any kind of collection except a map?
> For example, the some function takes a predicate function and a
> "coll", but it can't be a map.
I think it means any class that implements java.util.Collection.
This includes maps:
(some #(= (key %) :b) {:a 2 :b 3})
==> true
I think maps are generally treated as if you called "seq" on them,
i.e., as sequences of map-entries. You can get the key with "first"
or "key" and the value with "second" or "val", although the latter
options will tend to be much faster.
You can also destructure:
(some (fn [[k v]] (= k v)) {:a 2 :b :b})
==> true
-Jason
RSS Feed