Doesn't seem fair to use a sort algorithm in the implementation of selection sort. Besides, sort is an n*logn operation, so you don't want to (first (sort-by second ...)) anyway. Instead, choose (apply min-key second ...). Only catch is you need to make sure you don't pass an empty list, or it will throw an error rather than returning nil like the sort-by version.
selection-sort isn't going to be performant in an immutable data structure, but it might be interesting to compare performance using clojure.core.rrb-vector for faster removal of the minimum value. On Mon, Oct 10, 2016 at 6:33 AM, Moe Aboulkheir <m...@nervous.io> wrote: > Here's an example w/ iterate & a simpler 'smallest': > > (defn- smallest [xs] > (->> xs (map-indexed vector) (sort-by second) first)) > > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.