A few days ago I was thinking about how different it would be to write
flip-map* in Java vs Clojure. A very simple, small program, but easy
to see how Clojure can be more expressive.

public static Map<V,K> flipMap(Map<K,V> map)
{
    Map<V,K> result = new HashMap<V,K>(map.size());
    for (K key : map.keys()) {
        result.put(map.get(key), key);
    }

    return result;
}

(def flip-map #(apply zipmap ((juxt vals keys) %)))

* Given a hash map, reverse its keys and values such that every K=>V
pair in the input map becomes V=>K in the output. Naturally the values
must be unique for this to work, so call that a precondition.

On Sep 17, 2:47 pm, anderson_leite <anderson...@gmail.com> wrote:
> I'm new to clojure, so sorry if this is a dummie question.
>
> Studyng clojure I can understand the syntax and so on....but I would
> like a real example comparing clojure and java.
>
> Do you know some benchmark using first just java and than showing the
> best results with clojure ?

-- 
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 posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to