From a6deba0deeec8e5262e775d745832f6e77096dee Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Mon, 2 Dec 2019 13:35:15 -0500 Subject: [PATCH 1/2] Add Plus instance for Map --- src/Data/Map/Internal.purs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Data/Map/Internal.purs b/src/Data/Map/Internal.purs index 63b724a..4d5c573 100644 --- a/src/Data/Map/Internal.purs +++ b/src/Data/Map/Internal.purs @@ -48,6 +48,8 @@ module Data.Map.Internal import Prelude +import Control.Alt (class Alt) +import Control.Plus (class Plus) import Data.Eq (class Eq1) import Data.Foldable (foldl, foldMap, foldr, class Foldable) import Data.FoldableWithIndex (class FoldableWithIndex, foldlWithIndex, foldrWithIndex) @@ -149,6 +151,14 @@ instance traversableWithIndexMap :: TraversableWithIndex k (Map k) where <*> f k2 v2 <*> traverseWithIndex f right +instance altMap :: Ord k => Alt (Map k) + where + alt = union + +instance plusMap :: Ord k => Plus (Map k) + where + empty = empty + -- | Render a `Map` as a `String` showTree :: forall k v. Show k => Show v => Map k v -> String showTree Leaf = "Leaf" From 2ee99d27c87694033424d89dbbd748892da7dcab Mon Sep 17 00:00:00 2001 From: Asad Saeeduddin Date: Mon, 2 Dec 2019 13:40:30 -0500 Subject: [PATCH 2/2] Add Apply instance for Map --- src/Data/Map/Internal.purs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Data/Map/Internal.purs b/src/Data/Map/Internal.purs index 4d5c573..c9f8f4a 100644 --- a/src/Data/Map/Internal.purs +++ b/src/Data/Map/Internal.purs @@ -151,6 +151,12 @@ instance traversableWithIndexMap :: TraversableWithIndex k (Map k) where <*> f k2 v2 <*> traverseWithIndex f right +instance applyMap :: Ord k => Apply (Map k) + where + apply = applyFromLiftA2 intersectionWith + where + applyFromLiftA2 liftA2 = liftA2 identity + instance altMap :: Ord k => Alt (Map k) where alt = union