Hi,

On 3 Feb., 08:04, Petr Gladkikh <petrg...@gmail.com> wrote:

> Should not it be empty colection instead?
> It seems odd to me since it is inconsistent and forces to consider one
> more case (nil or collection).

It is consistent. There is a difference between () and nil. () is the
empty list. However there is no "empty sequence." Either there is
something or there is nothing. Why would you have to check for nil?
You can pass nil to any of the sequence library functions without fear
of harm. When you write such a function yourself, there is usually a
single check in the beginning when realising the sequence. Something
like (when-let [s (seq coll)] ...).

I never encountered any problems with this. Do you have a concrete
example where this causes trouble for you?

> And another question. I have written this function
> (defn index-by
>   "Make map (f x) -> x"
>   [f coll]
>   (reduce #(assoc %1 (f %2) %2) {} coll))
>
> I wonder, is there already such function somewhere in Clojure libraries?

You are probably looking for group-by, although it's slightly
different in that it collects all pre-images of a value (f x) in case
your function is not injective.

Sincerely
Meikel

-- 
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