aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Model/GraphObject.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/JLD/Model/GraphObject.hs')
-rw-r--r--src/Data/JLD/Model/GraphObject.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Data/JLD/Model/GraphObject.hs b/src/Data/JLD/Model/GraphObject.hs
new file mode 100644
index 0000000..3db9e6b
--- /dev/null
+++ b/src/Data/JLD/Model/GraphObject.hs
@@ -0,0 +1,22 @@
1module Data.JLD.Model.GraphObject (isGraphObject, isNotGraphObject, toGraphObject) where
2
3import Data.JLD.Prelude
4
5import Data.JLD.Model.Keyword (Keyword (..), isKeyword)
6
7import Data.Aeson (Object, Value (..))
8import Data.Aeson.Key qualified as K (toText)
9import Data.Aeson.KeyMap qualified as KM (keys, singleton, member)
10import Data.Vector qualified as V (singleton)
11
12isGraphObject :: Value -> Bool
13isGraphObject (Object o)
14 | KM.member (show KeywordGraph) o =
15 all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o)
16isGraphObject _ = False
17
18isNotGraphObject :: Value -> Bool
19isNotGraphObject = isGraphObject .> not
20
21toGraphObject :: Value -> Object
22toGraphObject = V.singleton .> Array .> KM.singleton (show KeywordGraph)