aboutsummaryrefslogtreecommitdiffstats
path: root/src/Data/JLD/Model/ValueObject.hs
blob: 79bd94fb79b0839adc8c616230dcd387fc3c1632 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Data.JLD.Model.ValueObject (isValueObject, isValueObject', isNotValueObject, isNotValueObject', valueObjectValue) where

import Data.JLD.Prelude

import Data.JLD.Model.Keyword (Keyword (..), isNotKeyword)

import Data.Aeson (Object, Value (..))
import Data.Aeson.Key qualified as K
import Data.Aeson.KeyMap qualified as KM

isValueObject :: Value -> Bool
isValueObject (Object o) = isValueObject' o
isValueObject _ = False

isValueObject' :: Object -> Bool
isValueObject' = KM.member (show KeywordValue)

isNotValueObject :: Value -> Bool
isNotValueObject (Object o) = isNotValueObject' o
isNotValueObject _ = False

isNotValueObject' :: Object -> Bool
isNotValueObject' = KM.keys .> fmap K.toText .> any (`isNotKeyword` [KeywordType, KeywordValue, KeywordDirection, KeywordLanguage, KeywordIndex])

valueObjectValue :: Value -> Maybe Value
valueObjectValue (Object o) = KM.lookup (show KeywordValue) o
valueObjectValue _ = Nothing