sorted-map-by constructs a persistent map whose keys follow a supplied two-argument comparator. Provide the comparator first, then an even number of key/value arguments; the result is a PersistentTreeMap. section 11.1.3
Order keys by a field
(sorted-map-by #(< (:age %1) (:age %2)) {:age 35} ["J" "K"] {:age 13} ["Q" "R"] {:age 14} ["T" "V"]) ;; {{:age 13} ["Q" "R"], {:age 14} ["T" "V"], {:age 35} ["J" "K"]}
Keep these behavioral details in mind:
- The comparator returns a negative, zero, or positive number for less-than, equality, or greater-than ordering. section 11.1.3
- Odd key/value arity throws IllegalArgumentException; incomparable or incompatible key types can throw ClassCastException. section 11.1.3
Use ordered maps in algorithms
A sorted map can act as a priority queue. An A* implementation initializes its frontier with (sorted-map-by compare [0 orig] [[] 0]) and repeatedly processes the lowest-scored entry. section 11.1.3
