Skip to content

Commit

Permalink
Add intersectionWith to Haskell.Data.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed May 9, 2024
1 parent 7183762 commit c77d6fd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/customer-deposit-wallet-pure/agda/Haskell/Data/Map.agda
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ unionWithMaybe f Nothing my = my
unionWithMaybe f (Just x) Nothing = Just x
unionWithMaybe f (Just x) (Just y) = Just (f x y)

intersectionWithMaybe : (f : a b c) Maybe a Maybe b Maybe c
intersectionWithMaybe f (Just x) (Just y) = Just (f x y)
intersectionWithMaybe _ _ _ = Nothing

{-----------------------------------------------------------------------------
Data.Map
------------------------------------------------------------------------------}
Expand Down Expand Up @@ -181,6 +185,16 @@ instance
iMapFoldable =
record {DefaultFoldable (record {foldMap = foldMap'})}

module _ {k a b c : Set} {{_ : Ord k}} where
postulate
intersectionWith : (a b c) Map k a Map k b Map k c

prop-lookup-intersectionWith
: (key : k) (ma : Map k a) (mb : Map k b)
(f : a b c)
lookup key (intersectionWith f ma mb)
≡ intersectionWithMaybe f (lookup key ma) (lookup key mb)

{-----------------------------------------------------------------------------
Test proofs
------------------------------------------------------------------------------}
Expand Down

0 comments on commit c77d6fd

Please sign in to comment.