diff options
Diffstat (limited to 'src/Data/JLD/Model/GraphObject.hs')
-rw-r--r-- | src/Data/JLD/Model/GraphObject.hs | 19 |
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 @@ | |||
1 | module Data.JLD.Model.GraphObject (isGraphObject, isNotGraphObject, toGraphObject) where | 1 | module Data.JLD.Model.GraphObject (isGraphObject, isGraphObject', isNotGraphObject, isNotGraphObject', toGraphObject) where |
2 | 2 | ||
3 | import Data.JLD.Prelude | 3 | import Data.JLD.Prelude |
4 | 4 | ||
@@ -6,17 +6,22 @@ import Data.JLD.Model.Keyword (Keyword (..), isKeyword) | |||
6 | 6 | ||
7 | import Data.Aeson (Object, Value (..)) | 7 | import Data.Aeson (Object, Value (..)) |
8 | import Data.Aeson.Key qualified as K (toText) | 8 | import Data.Aeson.Key qualified as K (toText) |
9 | import Data.Aeson.KeyMap qualified as KM (keys, singleton, member) | 9 | import Data.Aeson.KeyMap qualified as KM (keys, member, singleton) |
10 | import Data.Vector qualified as V (singleton) | ||
11 | 10 | ||
12 | isGraphObject :: Value -> Bool | 11 | isGraphObject :: Value -> Bool |
13 | isGraphObject (Object o) | 12 | isGraphObject (Object o) = isGraphObject' o |
14 | | KM.member (show KeywordGraph) o = | ||
15 | all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o) | ||
16 | isGraphObject _ = False | 13 | isGraphObject _ = False |
17 | 14 | ||
15 | isGraphObject' :: Object -> Bool | ||
16 | isGraphObject' o = | ||
17 | KM.member (show KeywordGraph) o | ||
18 | && all (`isKeyword` [KeywordGraph, KeywordId, KeywordIndex, KeywordContext]) (K.toText <$> KM.keys o) | ||
19 | |||
18 | isNotGraphObject :: Value -> Bool | 20 | isNotGraphObject :: Value -> Bool |
19 | isNotGraphObject = isGraphObject .> not | 21 | isNotGraphObject = isGraphObject .> not |
20 | 22 | ||
23 | isNotGraphObject' :: Object -> Bool | ||
24 | isNotGraphObject' = isGraphObject' .> not | ||
25 | |||
21 | toGraphObject :: Value -> Object | 26 | toGraphObject :: Value -> Object |
22 | toGraphObject = V.singleton .> Array .> KM.singleton (show KeywordGraph) | 27 | toGraphObject = pure .> Array .> KM.singleton (show KeywordGraph) |