aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Model/GraphObject.hs
diff options
context:
space:
mode:
authorVolpeon <github@volpeon.ink>2023-06-24 08:58:22 +0200
committerVolpeon <github@volpeon.ink>2023-06-24 08:58:22 +0200
commitb19440a4a30828f12f8eafaa7292152ecf733334 (patch)
tree00210fae1f860d76bb5319d10167d744c5d4037d /src/Data/JLD/Model/GraphObject.hs
parentSmall code optimization (diff)
downloadhs-jsonld-b19440a4a30828f12f8eafaa7292152ecf733334.tar.gz
hs-jsonld-b19440a4a30828f12f8eafaa7292152ecf733334.tar.bz2
hs-jsonld-b19440a4a30828f12f8eafaa7292152ecf733334.zip
WIP: Compaction
Diffstat (limited to 'src/Data/JLD/Model/GraphObject.hs')
-rw-r--r--src/Data/JLD/Model/GraphObject.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/Data/JLD/Model/GraphObject.hs b/src/Data/JLD/Model/GraphObject.hs
index 3db9e6b..4d7d3ad 100644
--- a/src/Data/JLD/Model/GraphObject.hs
+++ b/src/Data/JLD/Model/GraphObject.hs
@@ -1,4 +1,4 @@
1module Data.JLD.Model.GraphObject (isGraphObject, isNotGraphObject, toGraphObject) where 1module Data.JLD.Model.GraphObject (isGraphObject, isGraphObject', isNotGraphObject, isNotGraphObject', toGraphObject) where
2 2
3import Data.JLD.Prelude 3import Data.JLD.Prelude
4 4
@@ -6,17 +6,22 @@ import Data.JLD.Model.Keyword (Keyword (..), isKeyword)
6 6
7import Data.Aeson (Object, Value (..)) 7import Data.Aeson (Object, Value (..))
8import Data.Aeson.Key qualified as K (toText) 8import Data.Aeson.Key qualified as K (toText)
9import Data.Aeson.KeyMap qualified as KM (keys, singleton, member) 9import Data.Aeson.KeyMap qualified as KM (keys, member, singleton)
10import Data.Vector qualified as V (singleton)
11 10
12isGraphObject :: Value -> Bool 11isGraphObject :: Value -> Bool
13isGraphObject (Object o) 12isGraphObject (Object o) = isGraphObject' o
14 | KM.member (show KeywordGraph) o =
15 all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o)
16isGraphObject _ = False 13isGraphObject _ = False
17 14
15isGraphObject' :: Object -> Bool
16isGraphObject' o =
17 KM.member (show KeywordGraph) o
18 && all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o)
19
18isNotGraphObject :: Value -> Bool 20isNotGraphObject :: Value -> Bool
19isNotGraphObject = isGraphObject .> not 21isNotGraphObject = isGraphObject .> not
20 22
23isNotGraphObject' :: Object -> Bool
24isNotGraphObject' = isGraphObject' .> not
25
21toGraphObject :: Value -> Object 26toGraphObject :: Value -> Object
22toGraphObject = V.singleton .> Array .> KM.singleton (show KeywordGraph) 27toGraphObject = pure .> Array .> KM.singleton (show KeywordGraph)