From 8c49a30faa431b8b56a4b4926e7dae56b1311fea Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 28 May 2023 08:13:08 +0200 Subject: Completed untested Flattening implementation --- src/Data/JLD/Model/NodeMap.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Data/JLD/Model') diff --git a/src/Data/JLD/Model/NodeMap.hs b/src/Data/JLD/Model/NodeMap.hs index d0fb2f9..f76c662 100644 --- a/src/Data/JLD/Model/NodeMap.hs +++ b/src/Data/JLD/Model/NodeMap.hs @@ -10,13 +10,18 @@ module Data.JLD.Model.NodeMap ( hasKey2, hasKey3, memberArray, + propsToKeyMap, ) where import Data.JLD.Prelude hiding (modify) import Data.Aeson (Array, Value (..)) +import Data.Aeson.Key qualified as K +import Data.Aeson.KeyMap (KeyMap) +import Data.Aeson.KeyMap qualified as KM +import Data.Foldable.WithIndex (FoldableWithIndex (..)) import Data.JLD.Util (valueToArray) -import Data.Map.Strict qualified as M (alter, insert, lookup, member) +import Data.Map.Strict qualified as M (alter, insert, lookup, member, toList) type PropertyKey = Maybe Text type PropertyMap = Map PropertyKey Value @@ -55,3 +60,12 @@ memberArray :: GraphKey -> SubjectKey -> PropertyKey -> Value -> NodeMap -> Bool memberArray graphName subject property value nodeMap = case lookup3 graphName subject property nodeMap of Just (Array a) -> value `elem` a _ -> False + +propsToKeyMap :: PropertyMap -> KeyMap Value +propsToKeyMap = + ifoldl' + ( \maybeKey km value -> case maybeKey of + Just key -> KM.insert (K.fromText key) value km + Nothing -> km + ) + mempty -- cgit v1.2.3-70-g09d2