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, 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 m)))))))> 
> ...and vice versa:
>
> >   (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3, :b
> > 1, :c 2}
>
> (defn map-from-flat-collection [c]
>   (if (empty? c) {}
>     (conj (map-from-flat-collection (rrest c)) [(first c) (frest
> c)])))
>
> > Anyone have any idiomatic ideas?
>
> Well, not sure how idiomatic this is; apart from conj, this is how
> you'd do it in Lisp/Scheme. I'd use fold to do the first function if
> it's built into Clojure.
>
> Regards,
>
> --
> Michel
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to