make RingMap an instance of Traversable

- some examples tested out by hand, but not thorough test case or even
  QuickCheck coverage
k-choices
Trolli Schmittlauch 2020-10-07 19:24:15 +02:00
parent 048a6ce391
commit 6aebd982f8
1 changed files with 7 additions and 0 deletions

View File

@ -47,6 +47,13 @@ instance (Bounded k, Ord k) => Foldable (RingMap k) where
traversingFL acc (ProxyEntry _ Nothing) = acc
traversingFL acc (ProxyEntry _ (Just entry)) = traversingFL acc entry
instance (Bounded k, Ord k) => Traversable (RingMap k) where
traverse f = fmap RingMap . traverse traversingF . getRingMap
where
traversingF (KeyEntry entry) = KeyEntry <$> f entry
traversingF (ProxyEntry to Nothing) = pure $ ProxyEntry to Nothing
traversingF (ProxyEntry to (Just entry)) = ProxyEntry to . Just <$> traversingF entry
-- | entry of a 'RingMap' that holds a value and can also
-- wrap around the lookup direction at the edges of the name space.