Created
October 25, 2010 06:21
-
-
Save yayitswei/644489 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn map-keys [m f] | |
(into {} (for [[k v] m] [k (f v)]))) | |
;; recursive group-by | |
(defn group-by-> [starting-target starting-fns] | |
(loop [target starting-target fns starting-fns] | |
(if (nil? fns) target | |
(map-keys (group-by (first fns) target) #(recur % (rest fns)))))) | |
;; usage | |
(group-by-> [(time/date-time 2010 9 30) | |
(time/date-time 2010 10 1) | |
(time/date-time 2010 10 2) | |
(time/date-time 2010 10 2 1)] | |
[time/month time/day]) | |
;; {9 {30 [#<DateTime 2010-09-30T00:00:00.000Z>]} | |
;; 10 {1 [#<DateTime 2010-10-01T00:00:00.000Z>] | |
;; 2 [#<DateTime 2010-10-02T00:00:00.000Z> | |
;; #<DateTime 2010-10-02T01:00:00.000Z>]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment