conversion of RingMap to key-value list

k-choices
Trolli Schmittlauch 2020-09-18 20:26:20 +02:00
parent a1cfbbac48
commit 7dd7e96cce
1 changed files with 7 additions and 0 deletions

View File

@ -201,6 +201,13 @@ deleteRMapEntry nid = RingMap . Map.update modifier nid . getRingMap
rMapToList :: (Bounded k, Ord k) => RingMap k a -> [a]
rMapToList = mapMaybe extractRingEntry . Map.elems . getRingMap
rMapToListWithKeys :: (Bounded k, Ord k) => RingMap k a -> [(k, a)]
rMapToListWithKeys = Map.foldrWithKey (\k v acc ->
maybe acc (\val -> (k, val):acc) $ extractRingEntry v
)
[]
. getRingMap
rMapFromList :: (Bounded k, Ord k) => [(k, a)] -> RingMap k a
rMapFromList = setRMapEntries