1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

Define a lookup function for Map.

This commit is contained in:
Rob Rix 2018-03-07 12:44:05 -05:00
parent 00942f7073
commit 2aeab94001

View File

@ -2,16 +2,23 @@
-- | This module defines a 'Map' type whose 'Monoid' and 'Reducer' instances merge values using the 'Semigroup' instance for the underlying type.
module Data.Map.Monoidal
( Map
, lookup
, module Reducer
) where
import qualified Data.Map as Map
import Data.Semigroup.Reducer as Reducer
import Prelude hiding (lookup)
import Prologue hiding (Map)
newtype Map key value = Map (Map.Map key value)
newtype Map key value = Map { unMap :: Map.Map key value }
deriving (Eq, Eq1, Eq2, Foldable, Functor, Ord, Ord1, Ord2, Show, Show1, Show2, Traversable)
lookup :: Ord key => key -> Map key value -> Maybe value
lookup key = Map.lookup key . unMap
instance (Ord key, Semigroup value) => Semigroup (Map key value) where
Map a <> Map b = Map (Map.unionWith (<>) a b)