Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread samppi
Awesome. It amazes me what Clojure can do. Thanks for everyone's help. On Nov 15, 6:56 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > On Nov 15, 12:09 am, "Brian Doyle" <[EMAIL PROTECTED]> wrote: > > > Another way to create a map is: > > > user=> (apply hash-map [:a 1 :b 2 :c 3]) > > {:a 1, :c 3, :

Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread Rich Hickey
On Nov 15, 12:09 am, "Brian Doyle" <[EMAIL PROTECTED]> wrote: > Another way to create a map is: > > user=> (apply hash-map [:a 1 :b 2 :c 3]) > {:a 1, :c 3, :b 2} > Yes, that's fine, and for the flatten: (interleave (keys m) (vals m)) Rich > On Fri, Nov 14, 2008 at 9:42 PM, samppi <[EMAIL PR

Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread Kevin Downey
user=> (mapcat identity {:a 1 :b 2 :c 3}) (:c 3 :b 2 :a 1) On Sat, Nov 15, 2008 at 4:05 AM, Kevin Downey <[EMAIL PROTECTED]> wrote: > user=> (reduce concat {:a 1 :b 2 :c 3}) > (:c 3 :b 2 :a 1) > user=> > > > On Sat, Nov 15, 2008 at 4:02 AM, Matthias Benkard <[EMAIL PROTECTED]> wrote: >> >> On 1

Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread Matthias Benkard
On 15 Nov., 05:17, samppi <[EMAIL PROTECTED]> wrote: > Fold isn't build into Clojure Isn't fold just clojure/reduce? Matthias --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, s

Re: Getting a flat sequence from a map (and vice versa)

2008-11-15 Thread Kevin Downey
user=> (reduce concat {:a 1 :b 2 :c 3}) (:c 3 :b 2 :a 1) user=> On Sat, Nov 15, 2008 at 4:02 AM, Matthias Benkard <[EMAIL PROTECTED]> wrote: > > On 15 Nov., 05:17, samppi <[EMAIL PROTECTED]> wrote: >> Fold isn't build into Clojure > > Isn't fold just clojure/reduce? > > Matthias > > > -- The

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Brian Doyle
Another way to create a map is: user=> (apply hash-map [:a 1 :b 2 :c 3]) {:a 1, :c 3, :b 2} On Fri, Nov 14, 2008 at 9:42 PM, samppi <[EMAIL PROTECTED]> wrote: > > Excellent! I must remember about the apply function. Thank you very > much. > > On Nov 14, 9:35 pm, "Kevin Downey" <[EMAIL PROTECTED

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Kevin Downey
On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey <[EMAIL PROTECTED]> wrote: > On Fri, Nov 14, 2008 at 8:17 PM, samppi <[EMAIL PROTECTED]> wrote: >> >> Yeah, I need to be able to do this to easily manage trees of maps. I >> meant, how would you idiomatically implement their algorithms? >> >> Fold isn'

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread samppi
Excellent! I must remember about the apply function. Thank you very much. On Nov 14, 9:35 pm, "Kevin Downey" <[EMAIL PROTECTED]> wrote: > On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey <[EMAIL PROTECTED]> wrote: > > On Fri, Nov 14, 2008 at 8:17 PM, samppi <[EMAIL PROTECTED]> wrote: > > >> Yeah, I

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Kevin Downey
On Fri, Nov 14, 2008 at 8:17 PM, samppi <[EMAIL PROTECTED]> wrote: > > Yeah, I need to be able to do this to easily manage trees of maps. I > meant, how would you idiomatically implement their algorithms? > > Fold isn't build into Clojure, but they should still somehow be > possible...right? > > O

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread samppi
Yeah, I need to be able to do this to easily manage trees of maps. I meant, how would you idiomatically implement their algorithms? Fold isn't build into Clojure, but they should still somehow be possible...right? On Nov 14, 9:12 pm, Michel Salim <[EMAIL PROTECTED]> wrote: > On Nov 14, 10:56 pm,

Re: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Michel Salim
On Nov 14, 10:56 pm, samppi <[EMAIL PROTECTED]> wrote: > I'm trying to figure out how to do this: > >   (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) > (defn flat-map-seq [m] (if (empty? m) '() (let [kv (first m)] (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest

Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread samppi
I'm trying to figure out how to do this: (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2) ...and vice versa: (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b 1, :c 2} Anyone have any idiomatic ideas? --~--~-~--~~~---~--~~ You r