module Data.HashMap.Strict.Refined
(
Common.HashMap
, Common.Key
, Common.SomeHashMap(..)
, Common.withHashMap
, Common.SomeHashMapWith(..)
, Common.withHashMapWith
, Common.Some2HashMapWith(..)
, Common.with2HashMapWith
, SupersetProof(..)
, EmptyProof(..)
, Common.empty
, singleton
, SingletonProof(..)
, fromSet
, Common.fromHashMap
, fromTraversableWithKey
, FromTraversableProof(..)
, insert
, InsertProof(..)
, reinsert
, insertLookupWithKey
, Common.delete
, adjust
, adjustWithKey
, update
, updateLookupWithKey
, Common.lookup
, (Common.!)
, Common.member
, Common.null
, Common.isSubmapOfBy
, SubsetProof(..)
, Common.disjoint
, DisjointProof(..)
, zipWithKey
, bind
, unionWithKey
, UnionProof(..)
, Common.difference
, DifferenceProof(..)
, differenceWithKey
, PartialDifferenceProof(..)
, intersectionWithKey
, IntersectionProof(..)
, mapWithKey
, traverseWithKey
, mapAccumLWithKey
, mapAccumRWithKey
, mapKeysWith
, MapProof(..)
, backpermuteKeys
, Common.foldMapWithKey
, Common.foldrWithKey
, Common.foldlWithKey
, Common.foldrWithKey'
, Common.foldlWithKey'
, Common.toMap
, Common.keysSet
, Common.toList
, Common.restrictKeys
, Common.withoutKeys
, Common.filterWithKey
, Common.partitionWithKey
, PartitionProof(..)
, mapMaybeWithKey
, mapEitherWithKey
, Common.castKey
, Common.cast
, castFlavor
) where
import Data.Coerce
import Data.Container.Refined.Hashable
import Data.Container.Refined.Proofs
import Data.Container.Refined.Unsafe
import Data.Functor
import qualified Data.HashMap.Strict as HashMap
import Data.HashMap.Common.Refined
( HashMap(..), Key, unsafeCastKey, unsafeKey, SomeHashMapWith(..)
, Some2HashMapWith(..), (!)
)
import qualified Data.HashMap.Common.Refined as Common
import qualified Data.HashSet as HashSet
import Data.Proxy
import Data.Reflection
import Data.Traversable
import Data.Traversable.WithIndex
import Data.Type.Coercion
import Prelude hiding (lookup, null)
import Refined
import Refined.Unsafe
singleton
:: forall k a. Hashable k
=> k -> a -> SomeHashMapWith (SingletonProof 'Hashed k) k a
singleton :: forall k a.
Hashable k =>
k -> a -> SomeHashMapWith (SingletonProof 'Hashed k) k a
singleton k
k a
v = HashMap Any k a
-> SingletonProof 'Hashed k Any
-> SomeHashMapWith (SingletonProof 'Hashed k) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ k -> a -> HashMap k a
forall k v. Hashable k => k -> v -> HashMap k v
HashMap.singleton k
k a
v)
(SingletonProof 'Hashed k Any
-> SomeHashMapWith (SingletonProof 'Hashed k) k a)
-> SingletonProof 'Hashed k Any
-> SomeHashMapWith (SingletonProof 'Hashed k) k a
forall a b. (a -> b) -> a -> b
$ Refined (InSet 'Hashed Any) k -> SingletonProof 'Hashed k Any
forall (f :: Flavor) a r.
Refined (InSet f r) a -> SingletonProof f a r
SingletonProof (k -> Refined (InSet 'Hashed Any) k
forall k s. k -> Key s k
unsafeKey k
k)
fromSet :: forall s k a. KnownHashSet s k => (Key s k -> a) -> HashMap s k a
fromSet :: forall s k a. KnownHashSet s k => (Key s k -> a) -> HashMap s k a
fromSet Key s k -> a
f = HashMap k a -> HashMap s k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap s k a) -> HashMap k a -> HashMap s k a
forall a b. (a -> b) -> a -> b
$ (k -> () -> a) -> HashMap k () -> HashMap k a
forall k v1 v2. (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapWithKey (\k
k ()
_ -> Key s k -> a
f (Key s k -> a) -> Key s k -> a
forall a b. (a -> b) -> a -> b
$ k -> Key s k
forall k s. k -> Key s k
unsafeKey k
k)
(HashMap k () -> HashMap k a) -> HashMap k () -> HashMap k a
forall a b. (a -> b) -> a -> b
$ HashSet k -> HashMap k ()
forall a. HashSet a -> HashMap a ()
HashSet.toMap (Proxy s -> HashSet k
forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
forall (proxy :: * -> *). proxy s -> HashSet k
reflect (Proxy s -> HashSet k) -> Proxy s -> HashSet k
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @s)
fromTraversableWithKey
:: forall t k a. (Traversable t, Hashable k)
=> (k -> a -> a -> a)
-> t (k, a)
-> SomeHashMapWith (FromTraversableProof 'Hashed t k) k a
fromTraversableWithKey :: forall (t :: * -> *) k a.
(Traversable t, Hashable k) =>
(k -> a -> a -> a)
-> t (k, a)
-> SomeHashMapWith (FromTraversableProof 'Hashed t k) k a
fromTraversableWithKey k -> a -> a -> a
f t (k, a)
xs = HashMap Any k a
-> FromTraversableProof 'Hashed t k Any
-> SomeHashMapWith (FromTraversableProof 'Hashed t k) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap HashMap k a
m)
(FromTraversableProof 'Hashed t k Any
-> SomeHashMapWith (FromTraversableProof 'Hashed t k) k a)
-> FromTraversableProof 'Hashed t k Any
-> SomeHashMapWith (FromTraversableProof 'Hashed t k) k a
forall a b. (a -> b) -> a -> b
$ t (Refined (InSet 'Hashed Any) k)
-> FromTraversableProof 'Hashed t k Any
forall (f :: Flavor) (t :: * -> *) a r.
t (Refined (InSet f r) a) -> FromTraversableProof f t a r
FromTraversableProof t (Refined (InSet 'Hashed Any) k)
proof
where
(HashMap k a
m, t (Refined (InSet 'Hashed Any) k)
proof) = (HashMap k a
-> (k, a) -> (HashMap k a, Refined (InSet 'Hashed Any) k))
-> HashMap k a
-> t (k, a)
-> (HashMap k a, t (Refined (InSet 'Hashed Any) k))
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL
(\HashMap k a
s (k
k, a
v)
-> let !s' :: HashMap k a
s' = (a -> a -> a) -> k -> a -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
HashMap.insertWith (k -> a -> a -> a
f k
k) k
k a
v HashMap k a
s in (HashMap k a
s', k -> Refined (InSet 'Hashed Any) k
forall k s. k -> Key s k
unsafeKey k
k))
HashMap k a
forall k v. HashMap k v
HashMap.empty
t (k, a)
xs
insert
:: forall s k a. Hashable k
=> k -> a -> HashMap s k a -> SomeHashMapWith (InsertProof 'Hashed k s) k a
insert :: forall s k a.
Hashable k =>
k
-> a
-> HashMap s k a
-> SomeHashMapWith (InsertProof 'Hashed k s) k a
insert k
k a
v (HashMap HashMap k a
m) = HashMap Any k a
-> InsertProof 'Hashed k s Any
-> SomeHashMapWith (InsertProof 'Hashed k s) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ k -> a -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HashMap.insert k
k a
v HashMap k a
m)
(InsertProof 'Hashed k s Any
-> SomeHashMapWith (InsertProof 'Hashed k s) k a)
-> InsertProof 'Hashed k s Any
-> SomeHashMapWith (InsertProof 'Hashed k s) k a
forall a b. (a -> b) -> a -> b
$ Refined (InSet 'Hashed Any) k
-> (InSet 'Hashed s :-> InSet 'Hashed Any)
-> InsertProof 'Hashed k s Any
forall (f :: Flavor) a s r.
Refined (InSet f r) a
-> (InSet f s :-> InSet f r) -> InsertProof f a s r
InsertProof (k -> Refined (InSet 'Hashed Any) k
forall k s. k -> Key s k
unsafeKey k
k) Refined (InSet 'Hashed s) x -> Refined (InSet 'Hashed Any) x
InSet 'Hashed s :-> InSet 'Hashed Any
forall p q x. Refined p x -> Refined q x
unsafeSubset
reinsert
:: forall s k a. Hashable k
=> Key s k -> a -> HashMap s k a -> HashMap s k a
reinsert :: forall s k a.
Hashable k =>
Key s k -> a -> HashMap s k a -> HashMap s k a
reinsert = Coercion k (Key s k)
-> (Coercible k (Key s k) =>
Key s k -> a -> HashMap s k a -> HashMap s k a)
-> Key s k
-> a
-> HashMap s k a
-> HashMap s k a
forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s k. Coercion k (Key s k)
unsafeCastKey @s @k) ((Coercible k (Key s k) =>
Key s k -> a -> HashMap s k a -> HashMap s k a)
-> Key s k -> a -> HashMap s k a -> HashMap s k a)
-> (Coercible k (Key s k) =>
Key s k -> a -> HashMap s k a -> HashMap s k a)
-> Key s k
-> a
-> HashMap s k a
-> HashMap s k a
forall a b. (a -> b) -> a -> b
$ (k -> a -> HashMap k a -> HashMap k a)
-> Key s k -> a -> HashMap s k a -> HashMap s k a
forall a b. Coercible a b => a -> b
coerce ((k -> a -> HashMap k a -> HashMap k a)
-> Key s k -> a -> HashMap s k a -> HashMap s k a)
-> (k -> a -> HashMap k a -> HashMap k a)
-> Key s k
-> a
-> HashMap s k a
-> HashMap s k a
forall a b. (a -> b) -> a -> b
$ forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HashMap.insert @k @a
insertLookupWithKey
:: forall s k a. Hashable k
=> (Key s k -> a -> a -> a)
-> k
-> a
-> HashMap s k a
-> (Maybe (Key s k, a), SomeHashMapWith (InsertProof 'Hashed k s) k a)
insertLookupWithKey :: forall s k a.
Hashable k =>
(Key s k -> a -> a -> a)
-> k
-> a
-> HashMap s k a
-> (Maybe (Key s k, a),
SomeHashMapWith (InsertProof 'Hashed k s) k a)
insertLookupWithKey Key s k -> a -> a -> a
f k
k a
v (HashMap HashMap k a
m) =
( (k -> Key s k
forall k s. k -> Key s k
unsafeKey k
k,) (a -> (Key s k, a)) -> Maybe a -> Maybe (Key s k, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> HashMap k a -> Maybe a
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup k
k HashMap k a
m
, HashMap Any k a
-> InsertProof 'Hashed k s Any
-> SomeHashMapWith (InsertProof 'Hashed k s) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> k -> a -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
HashMap.insertWith (Key s k -> a -> a -> a
f (Key s k -> a -> a -> a) -> Key s k -> a -> a -> a
forall a b. (a -> b) -> a -> b
$ k -> Key s k
forall k s. k -> Key s k
unsafeKey k
k) k
k a
v HashMap k a
m)
(InsertProof 'Hashed k s Any
-> SomeHashMapWith (InsertProof 'Hashed k s) k a)
-> InsertProof 'Hashed k s Any
-> SomeHashMapWith (InsertProof 'Hashed k s) k a
forall a b. (a -> b) -> a -> b
$ Refined (InSet 'Hashed Any) k
-> (InSet 'Hashed s :-> InSet 'Hashed Any)
-> InsertProof 'Hashed k s Any
forall (f :: Flavor) a s r.
Refined (InSet f r) a
-> (InSet f s :-> InSet f r) -> InsertProof f a s r
InsertProof (k -> Refined (InSet 'Hashed Any) k
forall k s. k -> Key s k
unsafeKey k
k) Refined (InSet 'Hashed s) x -> Refined (InSet 'Hashed Any) x
InSet 'Hashed s :-> InSet 'Hashed Any
forall p q x. Refined p x -> Refined q x
unsafeSubset
)
adjust
:: forall s k a. Hashable k
=> (a -> a) -> Key s k -> HashMap s k a -> HashMap s k a
adjust :: forall s k a.
Hashable k =>
(a -> a) -> Key s k -> HashMap s k a -> HashMap s k a
adjust = Coercion k (Key s k)
-> (Coercible k (Key s k) =>
(a -> a) -> Key s k -> HashMap s k a -> HashMap s k a)
-> (a -> a)
-> Key s k
-> HashMap s k a
-> HashMap s k a
forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s k. Coercion k (Key s k)
unsafeCastKey @s @k) ((Coercible k (Key s k) =>
(a -> a) -> Key s k -> HashMap s k a -> HashMap s k a)
-> (a -> a) -> Key s k -> HashMap s k a -> HashMap s k a)
-> (Coercible k (Key s k) =>
(a -> a) -> Key s k -> HashMap s k a -> HashMap s k a)
-> (a -> a)
-> Key s k
-> HashMap s k a
-> HashMap s k a
forall a b. (a -> b) -> a -> b
$ ((a -> a) -> k -> HashMap k a -> HashMap k a)
-> (a -> a) -> Key s k -> HashMap s k a -> HashMap s k a
forall a b. Coercible a b => a -> b
coerce (((a -> a) -> k -> HashMap k a -> HashMap k a)
-> (a -> a) -> Key s k -> HashMap s k a -> HashMap s k a)
-> ((a -> a) -> k -> HashMap k a -> HashMap k a)
-> (a -> a)
-> Key s k
-> HashMap s k a
-> HashMap s k a
forall a b. (a -> b) -> a -> b
$ forall k v.
(Eq k, Hashable k) =>
(v -> v) -> k -> HashMap k v -> HashMap k v
HashMap.adjust @k @a
adjustWithKey
:: forall s k a. Hashable k
=> (Key s k -> a -> a) -> k -> HashMap s k a -> HashMap s k a
adjustWithKey :: forall s k a.
Hashable k =>
(Key s k -> a -> a) -> k -> HashMap s k a -> HashMap s k a
adjustWithKey Key s k -> a -> a
f k
k (HashMap HashMap k a
m) = HashMap k a -> HashMap s k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap s k a) -> HashMap k a -> HashMap s k a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> k -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
(v -> v) -> k -> HashMap k v -> HashMap k v
HashMap.adjust (Key s k -> a -> a
f (Key s k -> a -> a) -> Key s k -> a -> a
forall a b. (a -> b) -> a -> b
$ k -> Key s k
forall k s. k -> Key s k
unsafeKey k
k) k
k HashMap k a
m
update
:: forall s k a. Hashable k
=> (a -> Maybe a)
-> Key s k
-> HashMap s k a
-> SomeHashMapWith (SupersetProof 'Hashed s) k a
update :: forall s k a.
Hashable k =>
(a -> Maybe a)
-> Key s k
-> HashMap s k a
-> SomeHashMapWith (SupersetProof 'Hashed s) k a
update a -> Maybe a
f Key s k
k (HashMap HashMap k a
m)
= HashMap Any k a
-> SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
forall k a.
(Eq k, Hashable k) =>
(a -> Maybe a) -> k -> HashMap k a -> HashMap k a
HashMap.update a -> Maybe a
f (Key s k -> k
forall {k} (p :: k) x. Refined p x -> x
unrefine Key s k
k) HashMap k a
m)
(SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k a)
-> SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k a
forall a b. (a -> b) -> a -> b
$ (InSet 'Hashed Any :-> InSet 'Hashed s)
-> SupersetProof 'Hashed s Any
forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof Refined (InSet 'Hashed Any) x -> Refined (InSet 'Hashed s) x
InSet 'Hashed Any :-> InSet 'Hashed s
forall p q x. Refined p x -> Refined q x
unsafeSubset
updateLookupWithKey
:: forall s k a. Hashable k
=> (Key s k -> a -> Maybe a)
-> k
-> HashMap s k a
-> (Maybe (Key s k, a), SomeHashMapWith (SupersetProof 'Hashed s) k a)
updateLookupWithKey :: forall s k a.
Hashable k =>
(Key s k -> a -> Maybe a)
-> k
-> HashMap s k a
-> (Maybe (Key s k, a),
SomeHashMapWith (SupersetProof 'Hashed s) k a)
updateLookupWithKey Key s k -> a -> Maybe a
f k
k (HashMap HashMap k a
m) =
( (k -> Key s k
forall k s. k -> Key s k
unsafeKey k
k,) (a -> (Key s k, a)) -> Maybe a -> Maybe (Key s k, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> HashMap k a -> Maybe a
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup k
k HashMap k a
m
, HashMap Any k a
-> SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
forall k a.
(Eq k, Hashable k) =>
(a -> Maybe a) -> k -> HashMap k a -> HashMap k a
HashMap.update (Key s k -> a -> Maybe a
f (Key s k -> a -> Maybe a) -> Key s k -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ k -> Key s k
forall k s. k -> Key s k
unsafeKey k
k) k
k HashMap k a
m)
(SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k a)
-> SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k a
forall a b. (a -> b) -> a -> b
$ (InSet 'Hashed Any :-> InSet 'Hashed s)
-> SupersetProof 'Hashed s Any
forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof Refined (InSet 'Hashed Any) x -> Refined (InSet 'Hashed s) x
InSet 'Hashed Any :-> InSet 'Hashed s
forall p q x. Refined p x -> Refined q x
unsafeSubset
)
zipWithKey
:: forall s k a b c. Hashable k
=> (Key s k -> a -> b -> c) -> HashMap s k a -> HashMap s k b -> HashMap s k c
zipWithKey :: forall s k a b c.
Hashable k =>
(Key s k -> a -> b -> c)
-> HashMap s k a -> HashMap s k b -> HashMap s k c
zipWithKey = Coercion k (Key s k)
-> (Coercible k (Key s k) =>
(Key s k -> a -> b -> c)
-> HashMap s k a -> HashMap s k b -> HashMap s k c)
-> (Key s k -> a -> b -> c)
-> HashMap s k a
-> HashMap s k b
-> HashMap s k c
forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s k. Coercion k (Key s k)
unsafeCastKey @s @k) ((Coercible k (Key s k) =>
(Key s k -> a -> b -> c)
-> HashMap s k a -> HashMap s k b -> HashMap s k c)
-> (Key s k -> a -> b -> c)
-> HashMap s k a
-> HashMap s k b
-> HashMap s k c)
-> (Coercible k (Key s k) =>
(Key s k -> a -> b -> c)
-> HashMap s k a -> HashMap s k b -> HashMap s k c)
-> (Key s k -> a -> b -> c)
-> HashMap s k a
-> HashMap s k b
-> HashMap s k c
forall a b. (a -> b) -> a -> b
$ ((k -> a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c)
-> (Key s k -> a -> b -> c)
-> HashMap s k a
-> HashMap s k b
-> HashMap s k c
forall a b. Coercible a b => a -> b
coerce
(((k -> a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c)
-> (Key s k -> a -> b -> c)
-> HashMap s k a
-> HashMap s k b
-> HashMap s k c)
-> ((k -> a -> b -> c)
-> HashMap k a -> HashMap k b -> HashMap k c)
-> (Key s k -> a -> b -> c)
-> HashMap s k a
-> HashMap s k b
-> HashMap s k c
forall a b. (a -> b) -> a -> b
$ forall k v1 v2 v3.
(Eq k, Hashable k) =>
(k -> v1 -> v2 -> v3)
-> HashMap k v1 -> HashMap k v2 -> HashMap k v3
HashMap.intersectionWithKey @k @a @b @c
unionWithKey
:: forall s t k a. Hashable k
=> (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> a -> a)
-> HashMap s k a
-> HashMap t k a
-> SomeHashMapWith (UnionProof 'Hashed s t) k a
unionWithKey :: forall s t k a.
Hashable k =>
(Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> a -> a)
-> HashMap s k a
-> HashMap t k a
-> SomeHashMapWith (UnionProof 'Hashed s t) k a
unionWithKey Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> a -> a
f (HashMap HashMap k a
m1) (HashMap HashMap k a
m2) = HashMap Any k a
-> UnionProof 'Hashed s t Any
-> SomeHashMapWith (UnionProof 'Hashed s t) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith
(HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ (k -> a -> a -> a) -> HashMap k a -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
(k -> v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
HashMap.unionWithKey (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> a -> a
f (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> a -> a)
-> (k -> Refined (InSet 'Hashed s && InSet 'Hashed t) k)
-> k
-> a
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Refined (InSet 'Hashed s && InSet 'Hashed t) k
forall {k} x (p :: k). x -> Refined p x
reallyUnsafeRefine) HashMap k a
m1 HashMap k a
m2)
(UnionProof 'Hashed s t Any
-> SomeHashMapWith (UnionProof 'Hashed s t) k a)
-> UnionProof 'Hashed s t Any
-> SomeHashMapWith (UnionProof 'Hashed s t) k a
forall a b. (a -> b) -> a -> b
$ ((InSet 'Hashed s || InSet 'Hashed t) :-> InSet 'Hashed Any)
-> (forall u.
(InSet 'Hashed s :-> InSet 'Hashed u)
-> (InSet 'Hashed t :-> InSet 'Hashed u)
-> InSet 'Hashed Any :-> InSet 'Hashed u)
-> UnionProof 'Hashed s t Any
forall (f :: Flavor) s t r.
((InSet f s || InSet f t) :-> InSet f r)
-> (forall u.
(InSet f s :-> InSet f u)
-> (InSet f t :-> InSet f u) -> InSet f r :-> InSet f u)
-> UnionProof f s t r
UnionProof Refined (InSet 'Hashed s || InSet 'Hashed t) x
-> Refined (InSet 'Hashed Any) x
(InSet 'Hashed s || InSet 'Hashed t) :-> InSet 'Hashed Any
forall p q x. Refined p x -> Refined q x
unsafeSubset (InSet 'Hashed s :-> InSet 'Hashed u)
-> (InSet 'Hashed t :-> InSet 'Hashed u)
-> Refined (InSet 'Hashed Any) x
-> Refined (InSet 'Hashed u) x
(InSet 'Hashed s :-> InSet 'Hashed u)
-> (InSet 'Hashed t :-> InSet 'Hashed u)
-> InSet 'Hashed Any :-> InSet 'Hashed u
forall u.
(InSet 'Hashed s :-> InSet 'Hashed u)
-> (InSet 'Hashed t :-> InSet 'Hashed u)
-> InSet 'Hashed Any :-> InSet 'Hashed u
forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2
differenceWithKey
:: forall s t k a b. Hashable k
=> (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> Maybe a)
-> HashMap s k a
-> HashMap t k b
-> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a
differenceWithKey :: forall s t k a b.
Hashable k =>
(Refined (InSet 'Hashed s && InSet 'Hashed t) k
-> a -> b -> Maybe a)
-> HashMap s k a
-> HashMap t k b
-> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a
differenceWithKey Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> Maybe a
f (HashMap HashMap k a
m1) (HashMap HashMap k b
m2) = HashMap Any k a
-> PartialDifferenceProof 'Hashed s t Any
-> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith
(HashMap k a -> HashMap Any k a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k a -> HashMap Any k a) -> HashMap k a -> HashMap Any k a
forall a b. (a -> b) -> a -> b
$ (a -> (k, b) -> Maybe a)
-> HashMap k a -> HashMap k (k, b) -> HashMap k a
forall k v w.
(Eq k, Hashable k) =>
(v -> w -> Maybe v) -> HashMap k v -> HashMap k w -> HashMap k v
HashMap.differenceWith
(\a
x (k
k, b
y) -> Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> Maybe a
f (k -> Refined (InSet 'Hashed s && InSet 'Hashed t) k
forall {k} x (p :: k). x -> Refined p x
reallyUnsafeRefine k
k) a
x b
y)
HashMap k a
m1
((k -> b -> (k, b)) -> HashMap k b -> HashMap k (k, b)
forall k v1 v2. (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapWithKey (,) HashMap k b
m2))
(PartialDifferenceProof 'Hashed s t Any
-> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a)
-> PartialDifferenceProof 'Hashed s t Any
-> SomeHashMapWith (PartialDifferenceProof 'Hashed s t) k a
forall a b. (a -> b) -> a -> b
$ (InSet 'Hashed Any :-> InSet 'Hashed s)
-> (InSet 'Hashed s :-> (InSet 'Hashed t || InSet 'Hashed Any))
-> PartialDifferenceProof 'Hashed s t Any
forall (f :: Flavor) s t r.
(InSet f r :-> InSet f s)
-> (InSet f s :-> (InSet f t || InSet f r))
-> PartialDifferenceProof f s t r
PartialDifferenceProof Refined (InSet 'Hashed Any) x -> Refined (InSet 'Hashed s) x
InSet 'Hashed Any :-> InSet 'Hashed s
forall p q x. Refined p x -> Refined q x
unsafeSubset Refined (InSet 'Hashed s) x
-> Refined (InSet 'Hashed t || InSet 'Hashed Any) x
InSet 'Hashed s :-> (InSet 'Hashed t || InSet 'Hashed Any)
forall p q x. Refined p x -> Refined q x
unsafeSubset
intersectionWithKey
:: forall s t k a b c. Hashable k
=> (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> c)
-> HashMap s k a
-> HashMap t k b
-> SomeHashMapWith (IntersectionProof 'Hashed s t) k c
intersectionWithKey :: forall s t k a b c.
Hashable k =>
(Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> c)
-> HashMap s k a
-> HashMap t k b
-> SomeHashMapWith (IntersectionProof 'Hashed s t) k c
intersectionWithKey Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> c
f (HashMap HashMap k a
m1) (HashMap HashMap k b
m2) = HashMap Any k c
-> IntersectionProof 'Hashed s t Any
-> SomeHashMapWith (IntersectionProof 'Hashed s t) k c
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith
(HashMap k c -> HashMap Any k c
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k c -> HashMap Any k c) -> HashMap k c -> HashMap Any k c
forall a b. (a -> b) -> a -> b
$ (k -> a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c
forall k v1 v2 v3.
(Eq k, Hashable k) =>
(k -> v1 -> v2 -> v3)
-> HashMap k v1 -> HashMap k v2 -> HashMap k v3
HashMap.intersectionWithKey (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> c
f (Refined (InSet 'Hashed s && InSet 'Hashed t) k -> a -> b -> c)
-> (k -> Refined (InSet 'Hashed s && InSet 'Hashed t) k)
-> k
-> a
-> b
-> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Refined (InSet 'Hashed s && InSet 'Hashed t) k
forall {k} x (p :: k). x -> Refined p x
reallyUnsafeRefine) HashMap k a
m1 HashMap k b
m2)
(IntersectionProof 'Hashed s t Any
-> SomeHashMapWith (IntersectionProof 'Hashed s t) k c)
-> IntersectionProof 'Hashed s t Any
-> SomeHashMapWith (IntersectionProof 'Hashed s t) k c
forall a b. (a -> b) -> a -> b
$ (InSet 'Hashed Any :-> (InSet 'Hashed s && InSet 'Hashed t))
-> (forall u.
(InSet 'Hashed u :-> InSet 'Hashed s)
-> (InSet 'Hashed u :-> InSet 'Hashed t)
-> InSet 'Hashed u :-> InSet 'Hashed Any)
-> IntersectionProof 'Hashed s t Any
forall (f :: Flavor) s t r.
(InSet f r :-> (InSet f s && InSet f t))
-> (forall u.
(InSet f u :-> InSet f s)
-> (InSet f u :-> InSet f t) -> InSet f u :-> InSet f r)
-> IntersectionProof f s t r
IntersectionProof Refined (InSet 'Hashed Any) x
-> Refined (InSet 'Hashed s && InSet 'Hashed t) x
InSet 'Hashed Any :-> (InSet 'Hashed s && InSet 'Hashed t)
forall p q x. Refined p x -> Refined q x
unsafeSubset (InSet 'Hashed u :-> InSet 'Hashed s)
-> (InSet 'Hashed u :-> InSet 'Hashed t)
-> Refined (InSet 'Hashed u) x
-> Refined (InSet 'Hashed Any) x
(InSet 'Hashed u :-> InSet 'Hashed s)
-> (InSet 'Hashed u :-> InSet 'Hashed t)
-> InSet 'Hashed u :-> InSet 'Hashed Any
forall u.
(InSet 'Hashed u :-> InSet 'Hashed s)
-> (InSet 'Hashed u :-> InSet 'Hashed t)
-> InSet 'Hashed u :-> InSet 'Hashed Any
forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2
mapWithKey
:: forall s k a b. (Key s k -> a -> b) -> HashMap s k a -> HashMap s k b
mapWithKey :: forall s k a b.
(Key s k -> a -> b) -> HashMap s k a -> HashMap s k b
mapWithKey = Coercion k (Key s k)
-> (Coercible k (Key s k) =>
(Key s k -> a -> b) -> HashMap s k a -> HashMap s k b)
-> (Key s k -> a -> b)
-> HashMap s k a
-> HashMap s k b
forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s k. Coercion k (Key s k)
unsafeCastKey @s @k) ((Coercible k (Key s k) =>
(Key s k -> a -> b) -> HashMap s k a -> HashMap s k b)
-> (Key s k -> a -> b) -> HashMap s k a -> HashMap s k b)
-> (Coercible k (Key s k) =>
(Key s k -> a -> b) -> HashMap s k a -> HashMap s k b)
-> (Key s k -> a -> b)
-> HashMap s k a
-> HashMap s k b
forall a b. (a -> b) -> a -> b
$ ((k -> a -> b) -> HashMap k a -> HashMap k b)
-> (Key s k -> a -> b) -> HashMap s k a -> HashMap s k b
forall a b. Coercible a b => a -> b
coerce
(((k -> a -> b) -> HashMap k a -> HashMap k b)
-> (Key s k -> a -> b) -> HashMap s k a -> HashMap s k b)
-> ((k -> a -> b) -> HashMap k a -> HashMap k b)
-> (Key s k -> a -> b)
-> HashMap s k a
-> HashMap s k b
forall a b. (a -> b) -> a -> b
$ forall k v1 v2. (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapWithKey @k @a @b
traverseWithKey
:: forall s f k a b. Applicative f
=> (Key s k -> a -> f b) -> HashMap s k a -> f (HashMap s k b)
traverseWithKey :: forall s (f :: * -> *) k a b.
Applicative f =>
(Key s k -> a -> f b) -> HashMap s k a -> f (HashMap s k b)
traverseWithKey Key s k -> a -> f b
f (HashMap HashMap k a
m)
= HashMap k b -> HashMap s k b
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k b -> HashMap s k b)
-> f (HashMap k b) -> f (HashMap s k b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (k -> a -> f b) -> HashMap k a -> f (HashMap k b)
forall (f :: * -> *) k v1 v2.
Applicative f =>
(k -> v1 -> f v2) -> HashMap k v1 -> f (HashMap k v2)
HashMap.traverseWithKey (Key s k -> a -> f b
f (Key s k -> a -> f b) -> (k -> Key s k) -> k -> a -> f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Key s k
forall k s. k -> Key s k
unsafeKey) HashMap k a
m
mapAccumLWithKey
:: forall s k a b c. (a -> Key s k -> b -> (a, c))
-> a
-> HashMap s k b
-> (a, HashMap s k c)
mapAccumLWithKey :: forall s k a b c.
(a -> Key s k -> b -> (a, c))
-> a -> HashMap s k b -> (a, HashMap s k c)
mapAccumLWithKey a -> Key s k -> b -> (a, c)
f = (Key s k -> a -> b -> (a, c))
-> a -> HashMap s k b -> (a, HashMap s k c)
forall i (t :: * -> *) s a b.
TraversableWithIndex i t =>
(i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
imapAccumL ((a -> Key s k -> b -> (a, c)) -> Key s k -> a -> b -> (a, c)
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> Key s k -> b -> (a, c)
f)
mapAccumRWithKey
:: forall s k a b c. (a -> Key s k -> b -> (a, c))
-> a
-> HashMap s k b
-> (a, HashMap s k c)
mapAccumRWithKey :: forall s k a b c.
(a -> Key s k -> b -> (a, c))
-> a -> HashMap s k b -> (a, HashMap s k c)
mapAccumRWithKey a -> Key s k -> b -> (a, c)
f = (Key s k -> a -> b -> (a, c))
-> a -> HashMap s k b -> (a, HashMap s k c)
forall i (t :: * -> *) s a b.
TraversableWithIndex i t =>
(i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
imapAccumR ((a -> Key s k -> b -> (a, c)) -> Key s k -> a -> b -> (a, c)
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> Key s k -> b -> (a, c)
f)
mapKeysWith
:: forall s k1 k2 a. Hashable k2
=> (a -> a -> a)
-> (Key s k1 -> k2)
-> HashMap s k1 a
-> SomeHashMapWith (MapProof 'Hashed s k1 k2) k2 a
mapKeysWith :: forall s k1 k2 a.
Hashable k2 =>
(a -> a -> a)
-> (Key s k1 -> k2)
-> HashMap s k1 a
-> SomeHashMapWith (MapProof 'Hashed s k1 k2) k2 a
mapKeysWith a -> a -> a
f Key s k1 -> k2
g (HashMap HashMap k1 a
m) = HashMap Any k2 a
-> MapProof 'Hashed s k1 k2 Any
-> SomeHashMapWith (MapProof 'Hashed s k1 k2) k2 a
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith
(HashMap k2 a -> HashMap Any k2 a
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k2 a -> HashMap Any k2 a)
-> HashMap k2 a -> HashMap Any k2 a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> [(k2, a)] -> HashMap k2 a
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> [(k, v)] -> HashMap k v
HashMap.fromListWith a -> a -> a
f
([(k2, a)] -> HashMap k2 a) -> [(k2, a)] -> HashMap k2 a
forall a b. (a -> b) -> a -> b
$ (k1 -> a -> [(k2, a)] -> [(k2, a)])
-> [(k2, a)] -> HashMap k1 a -> [(k2, a)]
forall k v a. (k -> v -> a -> a) -> a -> HashMap k v -> a
HashMap.foldrWithKey (\k1
k a
x [(k2, a)]
xs -> (Key s k1 -> k2
g (Key s k1 -> k2) -> Key s k1 -> k2
forall a b. (a -> b) -> a -> b
$ k1 -> Key s k1
forall k s. k -> Key s k
unsafeKey k1
k, a
x) (k2, a) -> [(k2, a)] -> [(k2, a)]
forall a. a -> [a] -> [a]
: [(k2, a)]
xs) [] HashMap k1 a
m)
(MapProof 'Hashed s k1 k2 Any
-> SomeHashMapWith (MapProof 'Hashed s k1 k2) k2 a)
-> MapProof 'Hashed s k1 k2 Any
-> SomeHashMapWith (MapProof 'Hashed s k1 k2) k2 a
forall a b. (a -> b) -> a -> b
$ (Key s k1 -> Refined (InSet 'Hashed Any) k2)
-> (Refined (InSet 'Hashed Any) k2 -> Key s k1)
-> MapProof 'Hashed s k1 k2 Any
forall (f :: Flavor) s a b r.
(Refined (InSet f s) a -> Refined (InSet f r) b)
-> (Refined (InSet f r) b -> Refined (InSet f s) a)
-> MapProof f s a b r
MapProof (k2 -> Refined (InSet 'Hashed Any) k2
forall k s. k -> Key s k
unsafeKey (k2 -> Refined (InSet 'Hashed Any) k2)
-> (Key s k1 -> k2) -> Key s k1 -> Refined (InSet 'Hashed Any) k2
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key s k1 -> k2
g) \Refined (InSet 'Hashed Any) k2
k2 ->
case k2 -> HashMap k2 (Key s k1) -> Maybe (Key s k1)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Refined (InSet 'Hashed Any) k2 -> k2
forall {k} (p :: k) x. Refined p x -> x
unrefine Refined (InSet 'Hashed Any) k2
k2) HashMap k2 (Key s k1)
backMap of
Maybe (Key s k1)
Nothing -> [Char] -> Key s k1
forall a. HasCallStack => [Char] -> a
error
[Char]
"mapKeysWith: bug: Data.HashMap.Refined has been subverted"
Just Key s k1
k1 -> Key s k1
k1
where
~HashMap k2 (Key s k1)
backMap = [(k2, Key s k1)] -> HashMap k2 (Key s k1)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ (k2
k2, k1 -> Key s k1
forall k s. k -> Key s k
unsafeKey k1
k1)
| k1
k1 <- HashMap k1 a -> [k1]
forall k v. HashMap k v -> [k]
HashMap.keys HashMap k1 a
m
, let !k2 :: k2
k2 = Key s k1 -> k2
g (Key s k1 -> k2) -> Key s k1 -> k2
forall a b. (a -> b) -> a -> b
$ k1 -> Key s k1
forall k s. k -> Key s k
unsafeKey k1
k1
]
mapMaybeWithKey
:: forall s k a b. (Key s k -> a -> Maybe b)
-> HashMap s k a
-> SomeHashMapWith (SupersetProof 'Hashed s) k b
mapMaybeWithKey :: forall s k a b.
(Key s k -> a -> Maybe b)
-> HashMap s k a -> SomeHashMapWith (SupersetProof 'Hashed s) k b
mapMaybeWithKey Key s k -> a -> Maybe b
f (HashMap HashMap k a
m)
= HashMap Any k b
-> SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k b
forall s k a (p :: * -> *).
HashMap s k a -> p s -> SomeHashMapWith p k a
SomeHashMapWith (HashMap k b -> HashMap Any k b
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k b -> HashMap Any k b) -> HashMap k b -> HashMap Any k b
forall a b. (a -> b) -> a -> b
$ (k -> a -> Maybe b) -> HashMap k a -> HashMap k b
forall k v1 v2.
(k -> v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapMaybeWithKey (Key s k -> a -> Maybe b
f (Key s k -> a -> Maybe b) -> (k -> Key s k) -> k -> a -> Maybe b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Key s k
forall k s. k -> Key s k
unsafeKey) HashMap k a
m)
(SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k b)
-> SupersetProof 'Hashed s Any
-> SomeHashMapWith (SupersetProof 'Hashed s) k b
forall a b. (a -> b) -> a -> b
$ (InSet 'Hashed Any :-> InSet 'Hashed s)
-> SupersetProof 'Hashed s Any
forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof Refined (InSet 'Hashed Any) x -> Refined (InSet 'Hashed s) x
InSet 'Hashed Any :-> InSet 'Hashed s
forall p q x. Refined p x -> Refined q x
unsafeSubset
mapEitherWithKey
:: forall s k a b c. Hashable k
=> (Key s k -> a -> Either b c)
-> HashMap s k a
-> Some2HashMapWith (PartitionProof 'Hashed s k) k b c
mapEitherWithKey :: forall s k a b c.
Hashable k =>
(Key s k -> a -> Either b c)
-> HashMap s k a
-> Some2HashMapWith (PartitionProof 'Hashed s k) k b c
mapEitherWithKey Key s k -> a -> Either b c
p (HashMap HashMap k a
m)
| HashMap k (Either b c)
m' <- (k -> a -> Either b c) -> HashMap k a -> HashMap k (Either b c)
forall k v1 v2. (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapWithKey (Key s k -> a -> Either b c
p (Key s k -> a -> Either b c)
-> (k -> Key s k) -> k -> a -> Either b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Key s k
forall k s. k -> Key s k
unsafeKey) HashMap k a
m
= HashMap Any k b
-> HashMap Any k c
-> PartitionProof 'Hashed s k Any Any
-> Some2HashMapWith (PartitionProof 'Hashed s k) k b c
forall s t k a b (p :: * -> * -> *).
HashMap s k a -> HashMap t k b -> p s t -> Some2HashMapWith p k a b
Some2HashMapWith
(HashMap k b -> HashMap Any k b
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k b -> HashMap Any k b) -> HashMap k b -> HashMap Any k b
forall a b. (a -> b) -> a -> b
$ (Either b c -> Maybe b) -> HashMap k (Either b c) -> HashMap k b
forall v1 v2 k. (v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapMaybe ((b -> Maybe b) -> (c -> Maybe b) -> Either b c -> Maybe b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either b -> Maybe b
forall a. a -> Maybe a
Just (Maybe b -> c -> Maybe b
forall a b. a -> b -> a
const Maybe b
forall a. Maybe a
Nothing)) HashMap k (Either b c)
m')
(HashMap k c -> HashMap Any k c
forall s k a. HashMap k a -> HashMap s k a
HashMap (HashMap k c -> HashMap Any k c) -> HashMap k c -> HashMap Any k c
forall a b. (a -> b) -> a -> b
$ (Either b c -> Maybe c) -> HashMap k (Either b c) -> HashMap k c
forall v1 v2 k. (v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
HashMap.mapMaybe ((b -> Maybe c) -> (c -> Maybe c) -> Either b c -> Maybe c
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe c -> b -> Maybe c
forall a b. a -> b -> a
const Maybe c
forall a. Maybe a
Nothing) c -> Maybe c
forall a. a -> Maybe a
Just) HashMap k (Either b c)
m')
(PartitionProof 'Hashed s k Any Any
-> Some2HashMapWith (PartitionProof 'Hashed s k) k b c)
-> PartitionProof 'Hashed s k Any Any
-> Some2HashMapWith (PartitionProof 'Hashed s k) k b c
forall a b. (a -> b) -> a -> b
$ (Key s k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k))
-> ((InSet 'Hashed Any || InSet 'Hashed Any) :-> InSet 'Hashed s)
-> (forall t.
(InSet 'Hashed Any :-> InSet 'Hashed t)
-> (InSet 'Hashed Any :-> InSet 'Hashed t)
-> InSet 'Hashed s :-> InSet 'Hashed t)
-> (forall t.
(InSet 'Hashed t :-> InSet 'Hashed Any)
-> (InSet 'Hashed t :-> InSet 'Hashed Any)
-> forall u x.
Refined (InSet 'Hashed t) x -> Refined (InSet 'Hashed u) x)
-> PartitionProof 'Hashed s k Any Any
forall (f :: Flavor) s a r q.
(Refined (InSet f s) a
-> Either (Refined (InSet f r) a) (Refined (InSet f q) a))
-> ((InSet f r || InSet f q) :-> InSet f s)
-> (forall t.
(InSet f r :-> InSet f t)
-> (InSet f q :-> InSet f t) -> InSet f s :-> InSet f t)
-> (forall t.
(InSet f t :-> InSet f r)
-> (InSet f t :-> InSet f q)
-> forall u x. Refined (InSet f t) x -> Refined (InSet f u) x)
-> PartitionProof f s a r q
PartitionProof
do \Key s k
k -> case k -> HashMap k a -> Maybe a
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Key s k -> k
forall {k} (p :: k) x. Refined p x -> x
unrefine Key s k
k) HashMap k a
m of
Maybe a
Nothing -> [Char]
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k)
forall a. HasCallStack => [Char] -> a
error
[Char]
"mapEitherWithKey: bug: Data.HashMap.Refined has been subverted"
Just a
x -> case Key s k -> a -> Either b c
p Key s k
k a
x of
Left b
_ -> Refined (InSet 'Hashed Any) k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k)
forall a b. a -> Either a b
Left (Refined (InSet 'Hashed Any) k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k))
-> Refined (InSet 'Hashed Any) k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k)
forall a b. (a -> b) -> a -> b
$ k -> Refined (InSet 'Hashed Any) k
forall k s. k -> Key s k
unsafeKey (k -> Refined (InSet 'Hashed Any) k)
-> k -> Refined (InSet 'Hashed Any) k
forall a b. (a -> b) -> a -> b
$ Key s k -> k
forall {k} (p :: k) x. Refined p x -> x
unrefine Key s k
k
Right c
_ -> Refined (InSet 'Hashed Any) k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k)
forall a b. b -> Either a b
Right (Refined (InSet 'Hashed Any) k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k))
-> Refined (InSet 'Hashed Any) k
-> Either
(Refined (InSet 'Hashed Any) k) (Refined (InSet 'Hashed Any) k)
forall a b. (a -> b) -> a -> b
$ k -> Refined (InSet 'Hashed Any) k
forall k s. k -> Key s k
unsafeKey (k -> Refined (InSet 'Hashed Any) k)
-> k -> Refined (InSet 'Hashed Any) k
forall a b. (a -> b) -> a -> b
$ Key s k -> k
forall {k} (p :: k) x. Refined p x -> x
unrefine Key s k
k
Refined (InSet 'Hashed Any || InSet 'Hashed Any) x
-> Refined (InSet 'Hashed s) x
(InSet 'Hashed Any || InSet 'Hashed Any) :-> InSet 'Hashed s
forall p q x. Refined p x -> Refined q x
unsafeSubset (InSet 'Hashed Any :-> InSet 'Hashed t)
-> (InSet 'Hashed Any :-> InSet 'Hashed t)
-> Refined (InSet 'Hashed s) x
-> Refined (InSet 'Hashed t) x
(InSet 'Hashed Any :-> InSet 'Hashed t)
-> (InSet 'Hashed Any :-> InSet 'Hashed t)
-> InSet 'Hashed s :-> InSet 'Hashed t
forall t.
(InSet 'Hashed Any :-> InSet 'Hashed t)
-> (InSet 'Hashed Any :-> InSet 'Hashed t)
-> InSet 'Hashed s :-> InSet 'Hashed t
forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 \InSet 'Hashed t :-> InSet 'Hashed Any
f InSet 'Hashed t :-> InSet 'Hashed Any
g -> (InSet 'Hashed t :-> InSet 'Hashed Any)
-> (InSet 'Hashed t :-> InSet 'Hashed Any)
-> InSet 'Hashed t :-> InSet 'Hashed u
forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 Refined (InSet 'Hashed t) x -> Refined (InSet 'Hashed Any) x
InSet 'Hashed t :-> InSet 'Hashed Any
f Refined (InSet 'Hashed t) x -> Refined (InSet 'Hashed Any) x
InSet 'Hashed t :-> InSet 'Hashed Any
g
bind
:: forall s k a b. Hashable k
=> HashMap s k a -> (a -> HashMap s k b) -> HashMap s k b
bind :: forall s k a b.
Hashable k =>
HashMap s k a -> (a -> HashMap s k b) -> HashMap s k b
bind HashMap s k a
m a -> HashMap s k b
f = (Key s k -> a -> b) -> HashMap s k a -> HashMap s k b
forall s k a b.
(Key s k -> a -> b) -> HashMap s k a -> HashMap s k b
mapWithKey (\Key s k
k a
x -> a -> HashMap s k b
f a
x HashMap s k b -> Key s k -> b
forall s k a. Hashable k => HashMap s k a -> Key s k -> a
! Key s k
k) HashMap s k a
m
backpermuteKeys
:: forall s1 s2 k1 k2 a. (Hashable k1, KnownHashSet s2 k2)
=> (Key s2 k2 -> Key s1 k1) -> HashMap s1 k1 a -> HashMap s2 k2 a
backpermuteKeys :: forall s1 s2 k1 k2 a.
(Hashable k1, KnownHashSet s2 k2) =>
(Key s2 k2 -> Key s1 k1) -> HashMap s1 k1 a -> HashMap s2 k2 a
backpermuteKeys Key s2 k2 -> Key s1 k1
f HashMap s1 k1 a
m = (Key s2 k2 -> a) -> HashMap s2 k2 a
forall s k a. KnownHashSet s k => (Key s k -> a) -> HashMap s k a
fromSet \Key s2 k2
k -> HashMap s1 k1 a
m HashMap s1 k1 a -> Key s1 k1 -> a
forall s k a. Hashable k => HashMap s k a -> Key s k -> a
! Key s2 k2 -> Key s1 k1
f Key s2 k2
k