diff options
author | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2025-05-07 11:55:26 +0200 |
---|---|---|
committer | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2025-05-07 12:08:35 +0200 |
commit | eb57e21627ea404bc43fa8ebd0555c6f83a983e2 (patch) | |
tree | c759ff8a81916046dda20a048576ed8a1b9ce805 /src | |
parent | 8f15e78b68da61558ab7d09c1c330e7748992133 (diff) |
Factor out dSumToKV
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Dependent/EnumMap/Strict/Internal.hs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Data/Dependent/EnumMap/Strict/Internal.hs b/src/Data/Dependent/EnumMap/Strict/Internal.hs index 49fef13..c9dbcf1 100644 --- a/src/Data/Dependent/EnumMap/Strict/Internal.hs +++ b/src/Data/Dependent/EnumMap/Strict/Internal.hs @@ -32,6 +32,9 @@ class Enum1 f where fromEnum1 :: f a -> (Int, Enum1Info f) toEnum1 :: Int -> Enum1Info f -> Some f +dSumToKV :: Enum1 k => DSum k v -> (Int, KV k v) +dSumToKV (k :=> v) = let (i, inf) = fromEnum1 k in (i, KV inf v) + -- * Construction empty :: DEnumMap k v @@ -47,8 +50,7 @@ singleton k v = -- ** From Unordered Lists fromList :: Enum1 k => [DSum k v] -> DEnumMap k v -fromList l = - DEnumMap (IM.fromList (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) +fromList l = DEnumMap (IM.fromList (map dSumToKV l)) -- TODO: check that inf1 and inf2 match somehow? Comment why not needed or not possible, if so fromListWith :: Enum1 k @@ -57,7 +59,7 @@ fromListWith :: Enum1 k fromListWith f l = DEnumMap (IM.fromListWith (\(KV inf1 v1) (KV _ v2) -> KV inf1 (f (coe1 v1) (coe1 v2))) - (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) + (map dSumToKV l)) -- TODO: check that inf1 and inf2 match somehow? Comment why not needed or not possible, if so fromListWithKey :: Enum1 k @@ -67,13 +69,12 @@ fromListWithKey f l = DEnumMap (IM.fromListWithKey (\i (KV inf1 v1) (KV _ v2) -> case toEnum1 i inf1 of Some k -> KV inf1 (f k (coe1 v1) (coe1 v2))) - (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) + (map dSumToKV l)) -- ** From Ascending Lists fromAscList :: Enum1 k => [DSum k v] -> DEnumMap k v -fromAscList l = - DEnumMap (IM.fromAscList (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) +fromAscList l = DEnumMap (IM.fromAscList (map dSumToKV l)) -- TODO: check that inf1 and inf2 match somehow? Comment why not needed or not possible, if so fromAscListWith :: Enum1 k @@ -82,7 +83,7 @@ fromAscListWith :: Enum1 k fromAscListWith f l = DEnumMap (IM.fromAscListWith (\(KV inf1 v1) (KV _ v2) -> KV inf1 (f (coe1 v1) (coe1 v2))) - (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) + (map dSumToKV l)) -- TODO: check that inf1 and inf2 match somehow? Comment why not needed or not possible, if so fromAscListWithKey :: Enum1 k @@ -92,11 +93,10 @@ fromAscListWithKey f l = DEnumMap (IM.fromAscListWithKey (\i (KV inf1 v1) (KV _ v2) -> case toEnum1 i inf1 of Some k -> KV inf1 (f k (coe1 v1) (coe1 v2))) - (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) + (map dSumToKV l)) fromDistinctAscList :: Enum1 k => [DSum k v] -> DEnumMap k v -fromDistinctAscList l = - DEnumMap (IM.fromDistinctAscList (map (\(k :=> v) -> let (i, inf) = fromEnum1 k in (i, KV inf v)) l)) +fromDistinctAscList l = DEnumMap (IM.fromDistinctAscList (map dSumToKV l)) -- * Insertion |