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