Skip to content

Commit 1bb667b

Browse files
committed
fix: Invert filter behavior
1 parent e6960b2 commit 1bb667b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Handlers.hs

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import Data.Foldable (foldl')
1212
import Data.Maybe (catMaybes)
1313
import Data.Text.Lazy (Text,toStrict)
1414
import Data.Text.Lazy.Builder (toLazyText)
15-
import Data.HashMap.Strict (HashMap,(!),delete,keys,fromList,union,intersection,difference)
15+
import Data.HashMap.Strict (HashMap,(!),union,intersection,difference)
16+
import qualified Data.HashMap.Strict as HM
17+
import qualified Data.HashSet as HS
1618
import Data.Aeson (Value (Object))
1719
import Data.Aeson.Text (encodeToTextBuilder)
1820
import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder)
@@ -42,8 +44,10 @@ filterHandler
4244
= return
4345
. FilterRes
4446
. Object
45-
. foldl' (flip delete) filterDict
46-
$ toStrict <$> filterKeys
47+
. HM.filterWithKey (\k _ -> k `HS.member` keySet)
48+
$ filterDict
49+
where
50+
keySet = HS.fromList $ toStrict <$> filterKeys
4751

4852
filterHandler _
4953
= throwError
@@ -58,13 +62,13 @@ jsonDiff (Object dictA) (Object dictB) = Just (Object diffA,Object diffB)
5862
where
5963
addedA = dictA `difference` dictB
6064
addedB = dictB `difference` dictA
61-
alteredKeys = keys $ dictA `intersection` dictB
65+
alteredKeys = HM.keys $ dictA `intersection` dictB
6266
altered = catMaybes [withKey k $ jsonDiff (dictA ! k) (dictB ! k) | k <- alteredKeys]
6367
where
6468
withKey k (Just (x,y)) = Just ((k,x),(k,y))
6569
withKey k Nothing = Nothing
66-
alteredA = fromList $ fst <$> altered
67-
alteredB = fromList $ snd <$> altered
70+
alteredA = HM.fromList $ fst <$> altered
71+
alteredB = HM.fromList $ snd <$> altered
6872
diffA = addedA `union` alteredA
6973
diffB = addedB `union` alteredB
7074

0 commit comments

Comments
 (0)