Re: Create map from vector of keywords and other items

2013-02-21 Thread Stefan Kamphausen
Thank you all for your valuable input. I'll look into these soon. take-nthis definitely a function to keep in mind. Stefan -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that

Re: Create map from vector of keywords and other items

2013-02-20 Thread AtKaaZ
whatever the implementation I would include some example in the doc, like: (defn keycollect-*fnnamehere** " **input: [:key1 1 2 3 :key2 4 :key3 5 6 7] output: {:key1 [1 2 3] :key2 [4] :key3 [5 6 7]} "* [coll] ;... implementation here ) wish clojure has this kind of doc(s) instead,

Re: Create map from vector of keywords and other items

2013-02-20 Thread Elias Zaretsky
And this is mine (defn keycollect-too [key-fn coll] (let [not-key (complement key-fn)] (loop [[k & more] coll, res (transient {})] (let [[vv rr] (split-with not-key more)] (if-not k (persistent! res) (recur rr (assoc! res k (vec vv (keycollect-too k

Re: Create map from vector of keywords and other items

2013-02-20 Thread James Reichley
Here's my take: (defn partition' [coll] (let [coll' (partition-by keyword? coll)] (reduce merge {} (map vector (flatten (take-nth 2 coll')) (take-nth 2 (rest coll')) Note that this breaks if some keys point to empty sets On Wednesday, February 20, 2013 6:50:42 AM UTC-5, St

Re: Create map from vector of keywords and other items

2013-02-20 Thread Mauricio Aldazosa
Don't know if it's better, but: (apply hash-map (map-indexed #(if (= 0 (mod %1 2)) (first %2) (vec %2)) (partition-by keyword? [:key1 1 2 3 :key2 4 :key3 5 6 7]))) Seems to work. Mauricio -- -- You received this message because you are subscribed to the Google Gr

Re: Create map from vector of keywords and other items

2013-02-20 Thread Thomas Heller
Not sure if this is any more idiomatic, or feels any better, but I thought a loop would be appropriate here, plus I made key selection pluggable. https://gist.github.com/thheller/4995766 (defn split-into-map [items key-fn] "see gist") key-fn is a function which accepts one arg and should return

Re: Create map from vector of keywords and other items

2013-02-20 Thread Jim foo.bar
'keycollect-partition' looks sensible and idiomatic to me... perhaps juxt can come into play here? Of course, both versions will only work with keys as keywords and non-keys as non-keywords. If you use anything else other than a keyword for a key or a keyword for an item, both will break... J

Create map from vector of keywords and other items

2013-02-20 Thread Stefan Kamphausen
Hi, given a vector of the form [:key1 1 2 3 :key2 4 :key3 5 6 7] I wand to create a map collecting the items behind each keyword as a vector like this: {:key1 [1 2 3] :key2 [4] :key3 [5 6 7]} I have already written two functions which achieve this, but neither of them "feels good"