Lazy group-by for sorted maps?

130 views
Skip to first unread message

Colin Yates

unread,
Aug 12, 2013, 1:55:54 PM8/12/13
to clo...@googlegroups.com
Is there such a thing as a lazy group-by for a sequence of elements when the elements are sorted on the criteria used to group them?  I can imagine how one would look in a few lines of Clojure code but I am surprised there isn't one already.

My actual criteria is that I am pulling things from a database that live on the "many" side of a one-many and I want to sort on the "one" FK.

This is all based on the assumption that http://clojuredocs.org/clojure_core/clojure.core/group-by is eager!

Jonah Benton

unread,
Aug 12, 2013, 2:07:54 PM8/12/13
to clo...@googlegroups.com


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Colin Yates

unread,
Aug 12, 2013, 2:17:29 PM8/12/13
to clo...@googlegroups.com
Great - thanks!


You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/yGP0Ac_CUkY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Michael-Keith Bernard (SegFaultAX)

unread,
Aug 13, 2013, 12:56:16 AM8/13/13
to clo...@googlegroups.com
For the partition-by solution to work, you have to ensure that the result set from the query is sorted by the foreign key:

(partition-by identity "aaabbbcccaaabbbcc")
;;=> ((\a \a \a) (\b \b \b) (\c \c \c) (\a \a \a) (\b \b \b) (\c \c))
(partition-by identity (sort "aaabbbcccaaabbbcc"))
;;=> ((\a \a \a \a \a \a) (\b \b \b \b \b \b) (\c \c \c \c \c))

Colin Yates

unread,
Aug 13, 2013, 3:50:26 AM8/13/13
to clo...@googlegroups.com

Yep, sure.  Thanks.

Reply all
Reply to author
Forward
0 new messages