Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Add missing Functor/Foldable/Traversable instances for SymbolMap #703

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions asterius/src/Asterius/Types/SymbolMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ mapKeys fn = fromListSM . (map (\(k, e) -> (fn k, e))) . toListSM

-- ----------------------------------------------------------------------------

instance Functor SymbolMap where
fmap f (SymbolMap m) = SymbolMap $ IM.map (\(k, e) -> (k, f e)) m

instance Foldable SymbolMap where
foldr f z (SymbolMap m) = IM.foldr (\(_, e) b -> f e b) z m

instance Traversable SymbolMap where
traverse f (SymbolMap m) =
SymbolMap <$> traverse (\(k, x) -> fmap (\e -> (k, e)) (f x)) m

-- | /O(n*log n)/. Build a symbol map from a list of key/value pairs.
{-# INLINE fromListSM #-}
fromListSM :: [(EntitySymbol, a)] -> SymbolMap a
Expand Down