You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ordered provides sets and maps that maintain the insertion order of their contents.
Sets
(use 'flatland.ordered.set)
(ordered-set43182)
=> #ordered/set (43182)
(conj (ordered-set910) 123)
=> #ordered/set (910123)
(into (ordered-set) [76156])
=> #ordered/set (7615)
(disj (ordered-set81726) 7)
=> #ordered/set (8126)
;; Adding an element already in an ordered set does not change its;; position in the order.
(conj (ordered-set43182) 8)
=> #ordered/set (43182)
;; Removing an element, then adding it back in, puts it at the end,;; just as it would if it were never part of the set.
(-> (ordered-set43182) (disj8) (conj8))
=> #ordered/set (43128)
Maps
(use 'flatland.ordered.map)
(ordered-map:b2:a1:d4)
=> #ordered/map ([:b2] [:a1] [:d4])
(assoc (ordered-map:b2:a1:d4) :c3)
=> #ordered/map ([:b2] [:a1] [:d4] [:c3])
(into (ordered-map) [[:c3] [:a1] [:d4]])
=> #ordered/map ([:c3] [:a1] [:d4])
(dissoc (ordered-map:c3:a1:d4) :a)
=> #ordered/map ([:c3] [:d4])
;; Adding a key already in an ordered map does not change its position;; in the order.
(assoc (ordered-map:b2:a1:d4) :b7)
=> #ordered/map ([:b7] [:a1] [:d4])
;; Removing a key, then adding it back in, puts it at the end, just as;; it would if it were never part of the map.
(-> (ordered-map:b2:a1:d4) (dissoc:b) (assoc:b7))
=> #ordered/map ([:a1] [:d4] [:b7])
History
ordered was originally created by Alan Malloy and was part of the flatland organisation. In December 2018 it was moved to CLJ Commons for continued maintenance.