-- |
-- Module      : AutoProof.Internal.Utils.MapUtils
-- Copyright   : (c) Artem Mavrin, 2021
-- License     : BSD3
-- Maintainer  : artemvmavrin@gmail.com
-- Stability   : experimental
-- Portability : POSIX
--
-- Miscellaneous map-related functions.
module AutoProof.Internal.Utils.MapUtils (toMap) where

import Data.Map (Map)
import qualified Data.Map as Map

-- | Convert a foldable collection of (key, value) pairs into a map.
--
-- >>> set = Set.fromList [("a", 0), ("b", 1)]
-- >>> toMap set
-- fromList [("a",0),("b",1)]
toMap :: (Ord k, Foldable t) => t (k, v) -> Map k v
toMap :: t (k, v) -> Map k v
toMap = ((k, v) -> Map k v -> Map k v) -> Map k v -> t (k, v) -> Map k v
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((k -> v -> Map k v -> Map k v) -> (k, v) -> Map k v -> Map k v
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry k -> v -> Map k v -> Map k v
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert) Map k v
forall k a. Map k a
Map.empty