unable to sort a map containing date-time
You need to do this:
(sort-by (fn [[k v]] (-> v :time)) before? items)
In case you want a sorted-map then you need to make the date-time map as the key and :a :b as values cause sorted-map sort on key value:
(->> (into [] items)
(map (fn [[k v]] [v k]))
(flatten)
(apply sorted-map-by #(before? (%1 :time) (%2 :time))))
#(-> % items :month)
equivalents to
#(let [res1 (items %)
res2 (:month res1)]
res2)
res1
is always nil
because you give map entries of items
to it, so res2 is nil
too. And before?
throws this exception on nil
parameters.
Try this
(def items {:a {:time (date-time 2013 10)}
:c {:time (date-time 2013 12)}
:b {:time (date-time 2013 11)}})
(sort-by (comp :time second) before? items)
=> ([:a {:time #<DateTime 2013-10-01T00:00:00.000Z>}]
[:b {:time #<DateTime 2013-11-01T00:00:00.000Z>}]
[:c {:time #<DateTime 2013-12-01T00:00:00.000Z>}])