{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.Greskell.Graph.PropertyMap
(
PropertyMap (..)
, PropertyMapSingle
, PropertyMapList
, lookupOneValue
, lookupListValues
, parseOneValue
, parseListValues
, parseNonEmptyValues
, fromProperties
, FromGraphSONWithKey
, AProperty (..)
, AVertexProperty (..)
) where
import Control.Applicative (empty, (<|>))
import Data.Aeson (FromJSON (..))
import qualified Data.Aeson.Key as Key
import qualified Data.Aeson.KeyMap as KM
import Data.Aeson.Types (Parser)
import Data.Foldable (Foldable (..), foldlM)
import Data.Greskell.GraphSON (FromGraphSON (..), GValue, GraphSONTyped (..),
parseJSONViaGValue, (.:))
import Data.Greskell.GraphSON.GValue (GValueBody (..), gValueBody, gValueType)
import qualified Data.HashMap.Strict as HM
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NL
import Data.Maybe (listToMaybe)
import Data.Monoid (Monoid (..))
import Data.Semigroup (Semigroup ((<>)))
import qualified Data.Semigroup as Semigroup
import Data.Text (Text, unpack)
import Data.Traversable (Traversable (..))
import Data.Vector (Vector)
import Data.Greskell.Graph (AProperty (..), AVertexProperty (..), Property (..))
{-# DEPRECATED PropertyMap "PropertyMap and its instances are deprecated. Use PMap instead." #-}
class PropertyMap m where
lookupOne :: Text -> m p v -> Maybe (p v)
lookupOne Text
k m p v
m = forall a. [a] -> Maybe a
listToMaybe forall a b. (a -> b) -> a -> b
$ forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
PropertyMap m =>
Text -> m p v -> [p v]
lookupList Text
k m p v
m
lookupList :: Text -> m p v -> [p v]
putProperty :: Property p => p v -> m p v -> m p v
removeProperty :: Text -> m p v -> m p v
allProperties :: m p v -> [p v]
lookupOneValue :: (PropertyMap m, Property p) => Text -> m p v -> Maybe v
lookupOneValue :: forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p) =>
Text -> m p v -> Maybe v
lookupOneValue Text
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (p :: * -> *) v. Property p => p v -> v
propertyValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
PropertyMap m =>
Text -> m p v -> Maybe (p v)
lookupOne Text
k
lookupListValues :: (PropertyMap m, Property p) => Text -> m p v -> [v]
lookupListValues :: forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p) =>
Text -> m p v -> [v]
lookupListValues Text
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (p :: * -> *) v. Property p => p v -> v
propertyValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
PropertyMap m =>
Text -> m p v -> [p v]
lookupList Text
k
notExistErrorMsg :: Text -> String
notExistErrorMsg :: Text -> [Char]
notExistErrorMsg Text
k = [Char]
"Property '" forall a. [a] -> [a] -> [a]
++ Text -> [Char]
unpack Text
k forall a. [a] -> [a] -> [a]
++ [Char]
"' does not exist."
parseOneValue :: (PropertyMap m, Property p, FromGraphSON v) => Text -> m p GValue -> Parser v
parseOneValue :: forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p, FromGraphSON v) =>
Text -> m p GValue -> Parser v
parseOneValue Text
k m p GValue
pm = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
err_msg) forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON forall a b. (a -> b) -> a -> b
$ forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p) =>
Text -> m p v -> Maybe v
lookupOneValue Text
k m p GValue
pm
where
err_msg :: [Char]
err_msg = Text -> [Char]
notExistErrorMsg Text
k
parseListValues :: (PropertyMap m, Property p, FromGraphSON v) => Text -> m p GValue -> Parser [v]
parseListValues :: forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p, FromGraphSON v) =>
Text -> m p GValue -> Parser [v]
parseListValues Text
k m p GValue
pm = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON forall a b. (a -> b) -> a -> b
$ forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p) =>
Text -> m p v -> [v]
lookupListValues Text
k m p GValue
pm
parseNonEmptyValues :: (PropertyMap m, Property p, FromGraphSON v) => Text -> m p GValue -> Parser (NonEmpty v)
parseNonEmptyValues :: forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p, FromGraphSON v) =>
Text -> m p GValue -> Parser (NonEmpty v)
parseNonEmptyValues Text
k m p GValue
pm = forall {m :: * -> *} {a}. MonadFail m => [a] -> m (NonEmpty a)
toNonEmpty forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p, FromGraphSON v) =>
Text -> m p GValue -> Parser [v]
parseListValues Text
k m p GValue
pm
where
toNonEmpty :: [a] -> m (NonEmpty a)
toNonEmpty [] = forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail forall a b. (a -> b) -> a -> b
$ Text -> [Char]
notExistErrorMsg Text
k
toNonEmpty (a
x : [a]
rest) = forall (m :: * -> *) a. Monad m => a -> m a
return (a
x forall a. a -> [a] -> NonEmpty a
:| [a]
rest)
fromProperties :: (PropertyMap m, Property p, Monoid (m p v))
=> [p v]
-> m p v
fromProperties :: forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p, Monoid (m p v)) =>
[p v] -> m p v
fromProperties = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p) =>
p v -> m p v -> m p v
putProperty forall a. Monoid a => a
mempty
newtype PropertyMapGeneric t p v
= PropertyMapGeneric (HM.HashMap Text (t (p v)))
deriving (PropertyMapGeneric t p v -> PropertyMapGeneric t p v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (t :: * -> *) (p :: * -> *) v.
Eq (t (p v)) =>
PropertyMapGeneric t p v -> PropertyMapGeneric t p v -> Bool
/= :: PropertyMapGeneric t p v -> PropertyMapGeneric t p v -> Bool
$c/= :: forall (t :: * -> *) (p :: * -> *) v.
Eq (t (p v)) =>
PropertyMapGeneric t p v -> PropertyMapGeneric t p v -> Bool
== :: PropertyMapGeneric t p v -> PropertyMapGeneric t p v -> Bool
$c== :: forall (t :: * -> *) (p :: * -> *) v.
Eq (t (p v)) =>
PropertyMapGeneric t p v -> PropertyMapGeneric t p v -> Bool
Eq, Int -> PropertyMapGeneric t p v -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
forall (t :: * -> *) (p :: * -> *) v.
Show (t (p v)) =>
Int -> PropertyMapGeneric t p v -> ShowS
forall (t :: * -> *) (p :: * -> *) v.
Show (t (p v)) =>
[PropertyMapGeneric t p v] -> ShowS
forall (t :: * -> *) (p :: * -> *) v.
Show (t (p v)) =>
PropertyMapGeneric t p v -> [Char]
showList :: [PropertyMapGeneric t p v] -> ShowS
$cshowList :: forall (t :: * -> *) (p :: * -> *) v.
Show (t (p v)) =>
[PropertyMapGeneric t p v] -> ShowS
show :: PropertyMapGeneric t p v -> [Char]
$cshow :: forall (t :: * -> *) (p :: * -> *) v.
Show (t (p v)) =>
PropertyMapGeneric t p v -> [Char]
showsPrec :: Int -> PropertyMapGeneric t p v -> ShowS
$cshowsPrec :: forall (t :: * -> *) (p :: * -> *) v.
Show (t (p v)) =>
Int -> PropertyMapGeneric t p v -> ShowS
Show)
instance Semigroup (t (p v)) => Semigroup (PropertyMapGeneric t p v) where
(PropertyMapGeneric HashMap Text (t (p v))
a) <> :: PropertyMapGeneric t p v
-> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
<> (PropertyMapGeneric HashMap Text (t (p v))
b) = forall (t :: * -> *) (p :: * -> *) v.
HashMap Text (t (p v)) -> PropertyMapGeneric t p v
PropertyMapGeneric forall a b. (a -> b) -> a -> b
$ forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
HM.unionWith forall a. Semigroup a => a -> a -> a
(<>) HashMap Text (t (p v))
a HashMap Text (t (p v))
b
instance Semigroup (t (p v)) => Monoid (PropertyMapGeneric t p v) where
mempty :: PropertyMapGeneric t p v
mempty = forall (t :: * -> *) (p :: * -> *) v.
HashMap Text (t (p v)) -> PropertyMapGeneric t p v
PropertyMapGeneric forall a. Monoid a => a
mempty
mappend :: PropertyMapGeneric t p v
-> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance (Functor t, Functor p) => Functor (PropertyMapGeneric t p) where
fmap :: forall a b.
(a -> b) -> PropertyMapGeneric t p a -> PropertyMapGeneric t p b
fmap a -> b
f (PropertyMapGeneric HashMap Text (t (p a))
hm) = forall (t :: * -> *) (p :: * -> *) v.
HashMap Text (t (p v)) -> PropertyMapGeneric t p v
PropertyMapGeneric forall a b. (a -> b) -> a -> b
$ (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) a -> b
f HashMap Text (t (p a))
hm
instance (Foldable t, Foldable p) => Foldable (PropertyMapGeneric t p) where
foldr :: forall a b. (a -> b -> b) -> b -> PropertyMapGeneric t p a -> b
foldr a -> b -> b
f b
start (PropertyMapGeneric HashMap Text (t (p a))
hm) = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {t :: * -> *} {t :: * -> *}.
(Foldable t, Foldable t) =>
t (t a) -> b -> b
f2 b
start HashMap Text (t (p a))
hm
where
f2 :: t (t a) -> b -> b
f2 t (t a)
t b
start2 = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {t :: * -> *}. Foldable t => t a -> b -> b
f3 b
start2 t (t a)
t
f3 :: t a -> b -> b
f3 t a
p b
start3 = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> b -> b
f b
start3 t a
p
instance (Traversable t, Traversable p) => Traversable (PropertyMapGeneric t p) where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> PropertyMapGeneric t p a -> f (PropertyMapGeneric t p b)
traverse a -> f b
f (PropertyMapGeneric HashMap Text (t (p a))
hm) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (t :: * -> *) (p :: * -> *) v.
HashMap Text (t (p v)) -> PropertyMapGeneric t p v
PropertyMapGeneric forall a b. (a -> b) -> a -> b
$ (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse) a -> f b
f HashMap Text (t (p a))
hm
putPropertyGeneric :: (Semigroup (t (p v)), Applicative t, Property p) => p v -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
putPropertyGeneric :: forall (t :: * -> *) (p :: * -> *) v.
(Semigroup (t (p v)), Applicative t, Property p) =>
p v -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
putPropertyGeneric p v
prop (PropertyMapGeneric HashMap Text (t (p v))
hm) =
forall (t :: * -> *) (p :: * -> *) v.
HashMap Text (t (p v)) -> PropertyMapGeneric t p v
PropertyMapGeneric forall a b. (a -> b) -> a -> b
$ forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
HM.insertWith forall a. Semigroup a => a -> a -> a
(<>) (forall (p :: * -> *) v. Property p => p v -> Text
propertyKey p v
prop) (forall (f :: * -> *) a. Applicative f => a -> f a
pure p v
prop) HashMap Text (t (p v))
hm
removePropertyGeneric :: Text -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
removePropertyGeneric :: forall (t :: * -> *) (p :: * -> *) v.
Text -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
removePropertyGeneric Text
k (PropertyMapGeneric HashMap Text (t (p v))
hm) = forall (t :: * -> *) (p :: * -> *) v.
HashMap Text (t (p v)) -> PropertyMapGeneric t p v
PropertyMapGeneric forall a b. (a -> b) -> a -> b
$ forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
HM.delete Text
k HashMap Text (t (p v))
hm
allPropertiesGeneric :: Foldable t => PropertyMapGeneric t p v -> [p v]
allPropertiesGeneric :: forall (t :: * -> *) (p :: * -> *) v.
Foldable t =>
PropertyMapGeneric t p v -> [p v]
allPropertiesGeneric (PropertyMapGeneric HashMap Text (t (p v))
hm) = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall (t :: * -> *) a. Foldable t => t a -> [a]
toList forall a b. (a -> b) -> a -> b
$ forall k v. HashMap k v -> [v]
HM.elems HashMap Text (t (p v))
hm
parsePropertiesGeneric :: (Property p, PropertyMap m, Monoid (m p v), GraphSONTyped (p v), FromGraphSON (p v), FromGraphSONWithKey (p v))
=> (GValue -> Parser (Vector GValue))
-> GValue
-> Parser (m p v)
parsePropertiesGeneric :: forall (p :: * -> *) (m :: (* -> *) -> * -> *) v.
(Property p, PropertyMap m, Monoid (m p v), GraphSONTyped (p v),
FromGraphSON (p v), FromGraphSONWithKey (p v)) =>
(GValue -> Parser (Vector GValue)) -> GValue -> Parser (m p v)
parsePropertiesGeneric GValue -> Parser (Vector GValue)
normalizeCardinality GValue
gv = case GValue -> GValueBody
gValueBody GValue
gv of
GObject KeyMap GValue
obj -> forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldlM forall {m :: (* -> *) -> * -> *} {p :: * -> *} {v}.
(PropertyMap m, Property p, GraphSONTyped (p v),
FromGraphSON (p v), FromGraphSONWithKey (p v)) =>
m p v -> (Key, GValue) -> Parser (m p v)
folder forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$ forall v. KeyMap v -> [(Key, v)]
KM.toList KeyMap GValue
obj
GValueBody
_ -> forall (f :: * -> *) a. Alternative f => f a
empty
where
folder :: m p v -> (Key, GValue) -> Parser (m p v)
folder m p v
pm (Key
k, GValue
value) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
(PropertyMap m, Property p) =>
p v -> m p v -> m p v
putProperty m p v
pm) forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall {a}.
(GraphSONTyped a, FromGraphSON a, FromGraphSONWithKey a) =>
Key -> GValue -> Parser a
parseProperty Key
k) forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< GValue -> Parser (Vector GValue)
normalizeCardinality GValue
value
parseProperty :: Key -> GValue -> Parser a
parseProperty Key
k GValue
value = forall v. (GraphSONTyped v, FromGraphSON v) => GValue -> Parser v
parseTypedGValue GValue
value forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a. FromGraphSONWithKey a => Text -> GValue -> Parser a
parseGraphSONWithKey (Key -> Text
Key.toText Key
k) GValue
value
parseTypedGValue :: (GraphSONTyped v, FromGraphSON v) => GValue -> Parser v
parseTypedGValue :: forall v. (GraphSONTyped v, FromGraphSON v) => GValue -> Parser v
parseTypedGValue GValue
gv = do
v
prop <- forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON GValue
gv
let exp_type :: Text
exp_type = forall a. GraphSONTyped a => a -> Text
gsonTypeFor v
prop
mgot_type :: Maybe Text
mgot_type = GValue -> Maybe Text
gValueType GValue
gv
if Maybe Text
mgot_type forall a. Eq a => a -> a -> Bool
/= forall a. a -> Maybe a
Just Text
exp_type
then forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char]
"Expected @type field of " forall a. [a] -> [a] -> [a]
++ Text -> [Char]
unpack Text
exp_type forall a. [a] -> [a] -> [a]
++ [Char]
", but got " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Maybe Text
mgot_type)
else forall (m :: * -> *) a. Monad m => a -> m a
return v
prop
expectAesonArray :: GValue -> Parser (Vector GValue)
expectAesonArray :: GValue -> Parser (Vector GValue)
expectAesonArray GValue
gv = case GValue -> GValueBody
gValueBody GValue
gv of
GArray Vector GValue
a -> forall (m :: * -> *) a. Monad m => a -> m a
return Vector GValue
a
GValueBody
_ -> forall (f :: * -> *) a. Alternative f => f a
empty
newtype PropertyMapSingle p v
= PropertyMapSingle (PropertyMapGeneric Semigroup.First p v)
deriving (PropertyMapSingle p v -> PropertyMapSingle p v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (p :: * -> *) v.
Eq (p v) =>
PropertyMapSingle p v -> PropertyMapSingle p v -> Bool
/= :: PropertyMapSingle p v -> PropertyMapSingle p v -> Bool
$c/= :: forall (p :: * -> *) v.
Eq (p v) =>
PropertyMapSingle p v -> PropertyMapSingle p v -> Bool
== :: PropertyMapSingle p v -> PropertyMapSingle p v -> Bool
$c== :: forall (p :: * -> *) v.
Eq (p v) =>
PropertyMapSingle p v -> PropertyMapSingle p v -> Bool
Eq, forall a. Eq a => a -> PropertyMapSingle p a -> Bool
forall a. Num a => PropertyMapSingle p a -> a
forall a. Ord a => PropertyMapSingle p a -> a
forall m. Monoid m => PropertyMapSingle p m -> m
forall a. PropertyMapSingle p a -> Bool
forall a. PropertyMapSingle p a -> Int
forall a. PropertyMapSingle p a -> [a]
forall a. (a -> a -> a) -> PropertyMapSingle p a -> a
forall m a. Monoid m => (a -> m) -> PropertyMapSingle p a -> m
forall b a. (b -> a -> b) -> b -> PropertyMapSingle p a -> b
forall a b. (a -> b -> b) -> b -> PropertyMapSingle p a -> b
forall (p :: * -> *) a.
(Foldable p, Eq a) =>
a -> PropertyMapSingle p a -> Bool
forall (p :: * -> *) a.
(Foldable p, Num a) =>
PropertyMapSingle p a -> a
forall (p :: * -> *) a.
(Foldable p, Ord a) =>
PropertyMapSingle p a -> a
forall (p :: * -> *) m.
(Foldable p, Monoid m) =>
PropertyMapSingle p m -> m
forall (p :: * -> *) a. Foldable p => PropertyMapSingle p a -> Bool
forall (p :: * -> *) a. Foldable p => PropertyMapSingle p a -> Int
forall (p :: * -> *) a. Foldable p => PropertyMapSingle p a -> [a]
forall (p :: * -> *) a.
Foldable p =>
(a -> a -> a) -> PropertyMapSingle p a -> a
forall (p :: * -> *) m a.
(Foldable p, Monoid m) =>
(a -> m) -> PropertyMapSingle p a -> m
forall (p :: * -> *) b a.
Foldable p =>
(b -> a -> b) -> b -> PropertyMapSingle p a -> b
forall (p :: * -> *) a b.
Foldable p =>
(a -> b -> b) -> b -> PropertyMapSingle p a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => PropertyMapSingle p a -> a
$cproduct :: forall (p :: * -> *) a.
(Foldable p, Num a) =>
PropertyMapSingle p a -> a
sum :: forall a. Num a => PropertyMapSingle p a -> a
$csum :: forall (p :: * -> *) a.
(Foldable p, Num a) =>
PropertyMapSingle p a -> a
minimum :: forall a. Ord a => PropertyMapSingle p a -> a
$cminimum :: forall (p :: * -> *) a.
(Foldable p, Ord a) =>
PropertyMapSingle p a -> a
maximum :: forall a. Ord a => PropertyMapSingle p a -> a
$cmaximum :: forall (p :: * -> *) a.
(Foldable p, Ord a) =>
PropertyMapSingle p a -> a
elem :: forall a. Eq a => a -> PropertyMapSingle p a -> Bool
$celem :: forall (p :: * -> *) a.
(Foldable p, Eq a) =>
a -> PropertyMapSingle p a -> Bool
length :: forall a. PropertyMapSingle p a -> Int
$clength :: forall (p :: * -> *) a. Foldable p => PropertyMapSingle p a -> Int
null :: forall a. PropertyMapSingle p a -> Bool
$cnull :: forall (p :: * -> *) a. Foldable p => PropertyMapSingle p a -> Bool
toList :: forall a. PropertyMapSingle p a -> [a]
$ctoList :: forall (p :: * -> *) a. Foldable p => PropertyMapSingle p a -> [a]
foldl1 :: forall a. (a -> a -> a) -> PropertyMapSingle p a -> a
$cfoldl1 :: forall (p :: * -> *) a.
Foldable p =>
(a -> a -> a) -> PropertyMapSingle p a -> a
foldr1 :: forall a. (a -> a -> a) -> PropertyMapSingle p a -> a
$cfoldr1 :: forall (p :: * -> *) a.
Foldable p =>
(a -> a -> a) -> PropertyMapSingle p a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> PropertyMapSingle p a -> b
$cfoldl' :: forall (p :: * -> *) b a.
Foldable p =>
(b -> a -> b) -> b -> PropertyMapSingle p a -> b
foldl :: forall b a. (b -> a -> b) -> b -> PropertyMapSingle p a -> b
$cfoldl :: forall (p :: * -> *) b a.
Foldable p =>
(b -> a -> b) -> b -> PropertyMapSingle p a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> PropertyMapSingle p a -> b
$cfoldr' :: forall (p :: * -> *) a b.
Foldable p =>
(a -> b -> b) -> b -> PropertyMapSingle p a -> b
foldr :: forall a b. (a -> b -> b) -> b -> PropertyMapSingle p a -> b
$cfoldr :: forall (p :: * -> *) a b.
Foldable p =>
(a -> b -> b) -> b -> PropertyMapSingle p a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> PropertyMapSingle p a -> m
$cfoldMap' :: forall (p :: * -> *) m a.
(Foldable p, Monoid m) =>
(a -> m) -> PropertyMapSingle p a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> PropertyMapSingle p a -> m
$cfoldMap :: forall (p :: * -> *) m a.
(Foldable p, Monoid m) =>
(a -> m) -> PropertyMapSingle p a -> m
fold :: forall m. Monoid m => PropertyMapSingle p m -> m
$cfold :: forall (p :: * -> *) m.
(Foldable p, Monoid m) =>
PropertyMapSingle p m -> m
Foldable, forall a b. a -> PropertyMapSingle p b -> PropertyMapSingle p a
forall a b.
(a -> b) -> PropertyMapSingle p a -> PropertyMapSingle p b
forall (p :: * -> *) a b.
Functor p =>
a -> PropertyMapSingle p b -> PropertyMapSingle p a
forall (p :: * -> *) a b.
Functor p =>
(a -> b) -> PropertyMapSingle p a -> PropertyMapSingle p b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PropertyMapSingle p b -> PropertyMapSingle p a
$c<$ :: forall (p :: * -> *) a b.
Functor p =>
a -> PropertyMapSingle p b -> PropertyMapSingle p a
fmap :: forall a b.
(a -> b) -> PropertyMapSingle p a -> PropertyMapSingle p b
$cfmap :: forall (p :: * -> *) a b.
Functor p =>
(a -> b) -> PropertyMapSingle p a -> PropertyMapSingle p b
Functor, PropertyMapSingle p v
[PropertyMapSingle p v] -> PropertyMapSingle p v
PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall {p :: * -> *} {v}. Semigroup (PropertyMapSingle p v)
forall (p :: * -> *) v. PropertyMapSingle p v
forall (p :: * -> *) v.
[PropertyMapSingle p v] -> PropertyMapSingle p v
forall (p :: * -> *) v.
PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
mconcat :: [PropertyMapSingle p v] -> PropertyMapSingle p v
$cmconcat :: forall (p :: * -> *) v.
[PropertyMapSingle p v] -> PropertyMapSingle p v
mappend :: PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
$cmappend :: forall (p :: * -> *) v.
PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
mempty :: PropertyMapSingle p v
$cmempty :: forall (p :: * -> *) v. PropertyMapSingle p v
Monoid, NonEmpty (PropertyMapSingle p v) -> PropertyMapSingle p v
PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
forall b.
Integral b =>
b -> PropertyMapSingle p v -> PropertyMapSingle p v
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (p :: * -> *) v.
NonEmpty (PropertyMapSingle p v) -> PropertyMapSingle p v
forall (p :: * -> *) v.
PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
forall (p :: * -> *) v b.
Integral b =>
b -> PropertyMapSingle p v -> PropertyMapSingle p v
stimes :: forall b.
Integral b =>
b -> PropertyMapSingle p v -> PropertyMapSingle p v
$cstimes :: forall (p :: * -> *) v b.
Integral b =>
b -> PropertyMapSingle p v -> PropertyMapSingle p v
sconcat :: NonEmpty (PropertyMapSingle p v) -> PropertyMapSingle p v
$csconcat :: forall (p :: * -> *) v.
NonEmpty (PropertyMapSingle p v) -> PropertyMapSingle p v
<> :: PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
$c<> :: forall (p :: * -> *) v.
PropertyMapSingle p v
-> PropertyMapSingle p v -> PropertyMapSingle p v
Semigroup, Int -> PropertyMapSingle p v -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
forall (p :: * -> *) v.
Show (p v) =>
Int -> PropertyMapSingle p v -> ShowS
forall (p :: * -> *) v.
Show (p v) =>
[PropertyMapSingle p v] -> ShowS
forall (p :: * -> *) v.
Show (p v) =>
PropertyMapSingle p v -> [Char]
showList :: [PropertyMapSingle p v] -> ShowS
$cshowList :: forall (p :: * -> *) v.
Show (p v) =>
[PropertyMapSingle p v] -> ShowS
show :: PropertyMapSingle p v -> [Char]
$cshow :: forall (p :: * -> *) v.
Show (p v) =>
PropertyMapSingle p v -> [Char]
showsPrec :: Int -> PropertyMapSingle p v -> ShowS
$cshowsPrec :: forall (p :: * -> *) v.
Show (p v) =>
Int -> PropertyMapSingle p v -> ShowS
Show, forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall {p :: * -> *}.
Traversable p =>
Functor (PropertyMapSingle p)
forall {p :: * -> *}.
Traversable p =>
Foldable (PropertyMapSingle p)
forall (p :: * -> *) (m :: * -> *) a.
(Traversable p, Monad m) =>
PropertyMapSingle p (m a) -> m (PropertyMapSingle p a)
forall (p :: * -> *) (f :: * -> *) a.
(Traversable p, Applicative f) =>
PropertyMapSingle p (f a) -> f (PropertyMapSingle p a)
forall (p :: * -> *) (m :: * -> *) a b.
(Traversable p, Monad m) =>
(a -> m b) -> PropertyMapSingle p a -> m (PropertyMapSingle p b)
forall (p :: * -> *) (f :: * -> *) a b.
(Traversable p, Applicative f) =>
(a -> f b) -> PropertyMapSingle p a -> f (PropertyMapSingle p b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PropertyMapSingle p a -> f (PropertyMapSingle p b)
sequence :: forall (m :: * -> *) a.
Monad m =>
PropertyMapSingle p (m a) -> m (PropertyMapSingle p a)
$csequence :: forall (p :: * -> *) (m :: * -> *) a.
(Traversable p, Monad m) =>
PropertyMapSingle p (m a) -> m (PropertyMapSingle p a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PropertyMapSingle p a -> m (PropertyMapSingle p b)
$cmapM :: forall (p :: * -> *) (m :: * -> *) a b.
(Traversable p, Monad m) =>
(a -> m b) -> PropertyMapSingle p a -> m (PropertyMapSingle p b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PropertyMapSingle p (f a) -> f (PropertyMapSingle p a)
$csequenceA :: forall (p :: * -> *) (f :: * -> *) a.
(Traversable p, Applicative f) =>
PropertyMapSingle p (f a) -> f (PropertyMapSingle p a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PropertyMapSingle p a -> f (PropertyMapSingle p b)
$ctraverse :: forall (p :: * -> *) (f :: * -> *) a b.
(Traversable p, Applicative f) =>
(a -> f b) -> PropertyMapSingle p a -> f (PropertyMapSingle p b)
Traversable)
instance PropertyMap PropertyMapSingle where
lookupOne :: forall (p :: * -> *) v.
Text -> PropertyMapSingle p v -> Maybe (p v)
lookupOne Text
k (PropertyMapSingle (PropertyMapGeneric HashMap Text (First (p v))
hm)) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. First a -> a
Semigroup.getFirst forall a b. (a -> b) -> a -> b
$ forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup Text
k HashMap Text (First (p v))
hm
lookupList :: forall (p :: * -> *) v. Text -> PropertyMapSingle p v -> [p v]
lookupList Text
k PropertyMapSingle p v
m = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: (* -> *) -> * -> *) (p :: * -> *) v.
PropertyMap m =>
Text -> m p v -> Maybe (p v)
lookupOne Text
k PropertyMapSingle p v
m
putProperty :: forall (p :: * -> *) v.
Property p =>
p v -> PropertyMapSingle p v -> PropertyMapSingle p v
putProperty p v
p (PropertyMapSingle PropertyMapGeneric First p v
pg) = forall (p :: * -> *) v.
PropertyMapGeneric First p v -> PropertyMapSingle p v
PropertyMapSingle forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (p :: * -> *) v.
(Semigroup (t (p v)), Applicative t, Property p) =>
p v -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
putPropertyGeneric p v
p PropertyMapGeneric First p v
pg
removeProperty :: forall (p :: * -> *) v.
Text -> PropertyMapSingle p v -> PropertyMapSingle p v
removeProperty Text
t (PropertyMapSingle PropertyMapGeneric First p v
pg) = forall (p :: * -> *) v.
PropertyMapGeneric First p v -> PropertyMapSingle p v
PropertyMapSingle forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (p :: * -> *) v.
Text -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
removePropertyGeneric Text
t PropertyMapGeneric First p v
pg
allProperties :: forall (p :: * -> *) v. PropertyMapSingle p v -> [p v]
allProperties (PropertyMapSingle PropertyMapGeneric First p v
pg) = forall (t :: * -> *) (p :: * -> *) v.
Foldable t =>
PropertyMapGeneric t p v -> [p v]
allPropertiesGeneric PropertyMapGeneric First p v
pg
instance (Property p, GraphSONTyped (p v), FromGraphSON (p v), FromGraphSONWithKey (p v))
=> FromJSON (PropertyMapSingle p v) where
parseJSON :: Value -> Parser (PropertyMapSingle p v)
parseJSON = forall a. FromGraphSON a => Value -> Parser a
parseJSONViaGValue
instance (Property p, GraphSONTyped (p v), FromGraphSON (p v), FromGraphSONWithKey (p v))
=> FromGraphSON (PropertyMapSingle p v) where
parseGraphSON :: GValue -> Parser (PropertyMapSingle p v)
parseGraphSON = forall (p :: * -> *) (m :: (* -> *) -> * -> *) v.
(Property p, PropertyMap m, Monoid (m p v), GraphSONTyped (p v),
FromGraphSON (p v), FromGraphSONWithKey (p v)) =>
(GValue -> Parser (Vector GValue)) -> GValue -> Parser (m p v)
parsePropertiesGeneric (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return)
newtype PropertyMapList p v
= PropertyMapList (PropertyMapGeneric NonEmpty p v)
deriving (PropertyMapList p v -> PropertyMapList p v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (p :: * -> *) v.
Eq (p v) =>
PropertyMapList p v -> PropertyMapList p v -> Bool
/= :: PropertyMapList p v -> PropertyMapList p v -> Bool
$c/= :: forall (p :: * -> *) v.
Eq (p v) =>
PropertyMapList p v -> PropertyMapList p v -> Bool
== :: PropertyMapList p v -> PropertyMapList p v -> Bool
$c== :: forall (p :: * -> *) v.
Eq (p v) =>
PropertyMapList p v -> PropertyMapList p v -> Bool
Eq, forall a. Eq a => a -> PropertyMapList p a -> Bool
forall a. Num a => PropertyMapList p a -> a
forall a. Ord a => PropertyMapList p a -> a
forall m. Monoid m => PropertyMapList p m -> m
forall a. PropertyMapList p a -> Bool
forall a. PropertyMapList p a -> Int
forall a. PropertyMapList p a -> [a]
forall a. (a -> a -> a) -> PropertyMapList p a -> a
forall m a. Monoid m => (a -> m) -> PropertyMapList p a -> m
forall b a. (b -> a -> b) -> b -> PropertyMapList p a -> b
forall a b. (a -> b -> b) -> b -> PropertyMapList p a -> b
forall (p :: * -> *) a.
(Foldable p, Eq a) =>
a -> PropertyMapList p a -> Bool
forall (p :: * -> *) a.
(Foldable p, Num a) =>
PropertyMapList p a -> a
forall (p :: * -> *) a.
(Foldable p, Ord a) =>
PropertyMapList p a -> a
forall (p :: * -> *) m.
(Foldable p, Monoid m) =>
PropertyMapList p m -> m
forall (p :: * -> *) a. Foldable p => PropertyMapList p a -> Bool
forall (p :: * -> *) a. Foldable p => PropertyMapList p a -> Int
forall (p :: * -> *) a. Foldable p => PropertyMapList p a -> [a]
forall (p :: * -> *) a.
Foldable p =>
(a -> a -> a) -> PropertyMapList p a -> a
forall (p :: * -> *) m a.
(Foldable p, Monoid m) =>
(a -> m) -> PropertyMapList p a -> m
forall (p :: * -> *) b a.
Foldable p =>
(b -> a -> b) -> b -> PropertyMapList p a -> b
forall (p :: * -> *) a b.
Foldable p =>
(a -> b -> b) -> b -> PropertyMapList p a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => PropertyMapList p a -> a
$cproduct :: forall (p :: * -> *) a.
(Foldable p, Num a) =>
PropertyMapList p a -> a
sum :: forall a. Num a => PropertyMapList p a -> a
$csum :: forall (p :: * -> *) a.
(Foldable p, Num a) =>
PropertyMapList p a -> a
minimum :: forall a. Ord a => PropertyMapList p a -> a
$cminimum :: forall (p :: * -> *) a.
(Foldable p, Ord a) =>
PropertyMapList p a -> a
maximum :: forall a. Ord a => PropertyMapList p a -> a
$cmaximum :: forall (p :: * -> *) a.
(Foldable p, Ord a) =>
PropertyMapList p a -> a
elem :: forall a. Eq a => a -> PropertyMapList p a -> Bool
$celem :: forall (p :: * -> *) a.
(Foldable p, Eq a) =>
a -> PropertyMapList p a -> Bool
length :: forall a. PropertyMapList p a -> Int
$clength :: forall (p :: * -> *) a. Foldable p => PropertyMapList p a -> Int
null :: forall a. PropertyMapList p a -> Bool
$cnull :: forall (p :: * -> *) a. Foldable p => PropertyMapList p a -> Bool
toList :: forall a. PropertyMapList p a -> [a]
$ctoList :: forall (p :: * -> *) a. Foldable p => PropertyMapList p a -> [a]
foldl1 :: forall a. (a -> a -> a) -> PropertyMapList p a -> a
$cfoldl1 :: forall (p :: * -> *) a.
Foldable p =>
(a -> a -> a) -> PropertyMapList p a -> a
foldr1 :: forall a. (a -> a -> a) -> PropertyMapList p a -> a
$cfoldr1 :: forall (p :: * -> *) a.
Foldable p =>
(a -> a -> a) -> PropertyMapList p a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> PropertyMapList p a -> b
$cfoldl' :: forall (p :: * -> *) b a.
Foldable p =>
(b -> a -> b) -> b -> PropertyMapList p a -> b
foldl :: forall b a. (b -> a -> b) -> b -> PropertyMapList p a -> b
$cfoldl :: forall (p :: * -> *) b a.
Foldable p =>
(b -> a -> b) -> b -> PropertyMapList p a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> PropertyMapList p a -> b
$cfoldr' :: forall (p :: * -> *) a b.
Foldable p =>
(a -> b -> b) -> b -> PropertyMapList p a -> b
foldr :: forall a b. (a -> b -> b) -> b -> PropertyMapList p a -> b
$cfoldr :: forall (p :: * -> *) a b.
Foldable p =>
(a -> b -> b) -> b -> PropertyMapList p a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> PropertyMapList p a -> m
$cfoldMap' :: forall (p :: * -> *) m a.
(Foldable p, Monoid m) =>
(a -> m) -> PropertyMapList p a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> PropertyMapList p a -> m
$cfoldMap :: forall (p :: * -> *) m a.
(Foldable p, Monoid m) =>
(a -> m) -> PropertyMapList p a -> m
fold :: forall m. Monoid m => PropertyMapList p m -> m
$cfold :: forall (p :: * -> *) m.
(Foldable p, Monoid m) =>
PropertyMapList p m -> m
Foldable, forall a b. a -> PropertyMapList p b -> PropertyMapList p a
forall a b. (a -> b) -> PropertyMapList p a -> PropertyMapList p b
forall (p :: * -> *) a b.
Functor p =>
a -> PropertyMapList p b -> PropertyMapList p a
forall (p :: * -> *) a b.
Functor p =>
(a -> b) -> PropertyMapList p a -> PropertyMapList p b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PropertyMapList p b -> PropertyMapList p a
$c<$ :: forall (p :: * -> *) a b.
Functor p =>
a -> PropertyMapList p b -> PropertyMapList p a
fmap :: forall a b. (a -> b) -> PropertyMapList p a -> PropertyMapList p b
$cfmap :: forall (p :: * -> *) a b.
Functor p =>
(a -> b) -> PropertyMapList p a -> PropertyMapList p b
Functor, PropertyMapList p v
[PropertyMapList p v] -> PropertyMapList p v
PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall {p :: * -> *} {v}. Semigroup (PropertyMapList p v)
forall (p :: * -> *) v. PropertyMapList p v
forall (p :: * -> *) v.
[PropertyMapList p v] -> PropertyMapList p v
forall (p :: * -> *) v.
PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
mconcat :: [PropertyMapList p v] -> PropertyMapList p v
$cmconcat :: forall (p :: * -> *) v.
[PropertyMapList p v] -> PropertyMapList p v
mappend :: PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
$cmappend :: forall (p :: * -> *) v.
PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
mempty :: PropertyMapList p v
$cmempty :: forall (p :: * -> *) v. PropertyMapList p v
Monoid, NonEmpty (PropertyMapList p v) -> PropertyMapList p v
PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
forall b.
Integral b =>
b -> PropertyMapList p v -> PropertyMapList p v
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (p :: * -> *) v.
NonEmpty (PropertyMapList p v) -> PropertyMapList p v
forall (p :: * -> *) v.
PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
forall (p :: * -> *) v b.
Integral b =>
b -> PropertyMapList p v -> PropertyMapList p v
stimes :: forall b.
Integral b =>
b -> PropertyMapList p v -> PropertyMapList p v
$cstimes :: forall (p :: * -> *) v b.
Integral b =>
b -> PropertyMapList p v -> PropertyMapList p v
sconcat :: NonEmpty (PropertyMapList p v) -> PropertyMapList p v
$csconcat :: forall (p :: * -> *) v.
NonEmpty (PropertyMapList p v) -> PropertyMapList p v
<> :: PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
$c<> :: forall (p :: * -> *) v.
PropertyMapList p v -> PropertyMapList p v -> PropertyMapList p v
Semigroup, Int -> PropertyMapList p v -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
forall (p :: * -> *) v.
Show (p v) =>
Int -> PropertyMapList p v -> ShowS
forall (p :: * -> *) v.
Show (p v) =>
[PropertyMapList p v] -> ShowS
forall (p :: * -> *) v. Show (p v) => PropertyMapList p v -> [Char]
showList :: [PropertyMapList p v] -> ShowS
$cshowList :: forall (p :: * -> *) v.
Show (p v) =>
[PropertyMapList p v] -> ShowS
show :: PropertyMapList p v -> [Char]
$cshow :: forall (p :: * -> *) v. Show (p v) => PropertyMapList p v -> [Char]
showsPrec :: Int -> PropertyMapList p v -> ShowS
$cshowsPrec :: forall (p :: * -> *) v.
Show (p v) =>
Int -> PropertyMapList p v -> ShowS
Show, forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall {p :: * -> *}. Traversable p => Functor (PropertyMapList p)
forall {p :: * -> *}. Traversable p => Foldable (PropertyMapList p)
forall (p :: * -> *) (m :: * -> *) a.
(Traversable p, Monad m) =>
PropertyMapList p (m a) -> m (PropertyMapList p a)
forall (p :: * -> *) (f :: * -> *) a.
(Traversable p, Applicative f) =>
PropertyMapList p (f a) -> f (PropertyMapList p a)
forall (p :: * -> *) (m :: * -> *) a b.
(Traversable p, Monad m) =>
(a -> m b) -> PropertyMapList p a -> m (PropertyMapList p b)
forall (p :: * -> *) (f :: * -> *) a b.
(Traversable p, Applicative f) =>
(a -> f b) -> PropertyMapList p a -> f (PropertyMapList p b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PropertyMapList p a -> f (PropertyMapList p b)
sequence :: forall (m :: * -> *) a.
Monad m =>
PropertyMapList p (m a) -> m (PropertyMapList p a)
$csequence :: forall (p :: * -> *) (m :: * -> *) a.
(Traversable p, Monad m) =>
PropertyMapList p (m a) -> m (PropertyMapList p a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PropertyMapList p a -> m (PropertyMapList p b)
$cmapM :: forall (p :: * -> *) (m :: * -> *) a b.
(Traversable p, Monad m) =>
(a -> m b) -> PropertyMapList p a -> m (PropertyMapList p b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PropertyMapList p (f a) -> f (PropertyMapList p a)
$csequenceA :: forall (p :: * -> *) (f :: * -> *) a.
(Traversable p, Applicative f) =>
PropertyMapList p (f a) -> f (PropertyMapList p a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PropertyMapList p a -> f (PropertyMapList p b)
$ctraverse :: forall (p :: * -> *) (f :: * -> *) a b.
(Traversable p, Applicative f) =>
(a -> f b) -> PropertyMapList p a -> f (PropertyMapList p b)
Traversable)
instance PropertyMap PropertyMapList where
lookupList :: forall (p :: * -> *) v. Text -> PropertyMapList p v -> [p v]
lookupList Text
k (PropertyMapList (PropertyMapGeneric HashMap Text (NonEmpty (p v))
hm)) = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] forall a. NonEmpty a -> [a]
NL.toList forall a b. (a -> b) -> a -> b
$ forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup Text
k HashMap Text (NonEmpty (p v))
hm
putProperty :: forall (p :: * -> *) v.
Property p =>
p v -> PropertyMapList p v -> PropertyMapList p v
putProperty p v
p (PropertyMapList PropertyMapGeneric NonEmpty p v
pg) = forall (p :: * -> *) v.
PropertyMapGeneric NonEmpty p v -> PropertyMapList p v
PropertyMapList forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (p :: * -> *) v.
(Semigroup (t (p v)), Applicative t, Property p) =>
p v -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
putPropertyGeneric p v
p PropertyMapGeneric NonEmpty p v
pg
removeProperty :: forall (p :: * -> *) v.
Text -> PropertyMapList p v -> PropertyMapList p v
removeProperty Text
t (PropertyMapList PropertyMapGeneric NonEmpty p v
pg) = forall (p :: * -> *) v.
PropertyMapGeneric NonEmpty p v -> PropertyMapList p v
PropertyMapList forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (p :: * -> *) v.
Text -> PropertyMapGeneric t p v -> PropertyMapGeneric t p v
removePropertyGeneric Text
t PropertyMapGeneric NonEmpty p v
pg
allProperties :: forall (p :: * -> *) v. PropertyMapList p v -> [p v]
allProperties (PropertyMapList PropertyMapGeneric NonEmpty p v
pg) = forall (t :: * -> *) (p :: * -> *) v.
Foldable t =>
PropertyMapGeneric t p v -> [p v]
allPropertiesGeneric PropertyMapGeneric NonEmpty p v
pg
instance (Property p, GraphSONTyped (p v), FromGraphSON (p v), FromGraphSONWithKey (p v))
=> FromJSON (PropertyMapList p v) where
parseJSON :: Value -> Parser (PropertyMapList p v)
parseJSON = forall a. FromGraphSON a => Value -> Parser a
parseJSONViaGValue
instance (Property p, GraphSONTyped (p v), FromGraphSON (p v), FromGraphSONWithKey (p v))
=> FromGraphSON (PropertyMapList p v) where
parseGraphSON :: GValue -> Parser (PropertyMapList p v)
parseGraphSON GValue
v = forall (p :: * -> *) (m :: (* -> *) -> * -> *) v.
(Property p, PropertyMap m, Monoid (m p v), GraphSONTyped (p v),
FromGraphSON (p v), FromGraphSONWithKey (p v)) =>
(GValue -> Parser (Vector GValue)) -> GValue -> Parser (m p v)
parsePropertiesGeneric GValue -> Parser (Vector GValue)
expectAesonArray GValue
v
class FromGraphSONWithKey a where
parseGraphSONWithKey :: Text -> GValue -> Parser a
instance FromGraphSON v => FromGraphSONWithKey (AProperty v) where
parseGraphSONWithKey :: Text -> GValue -> Parser (AProperty v)
parseGraphSONWithKey Text
k GValue
v = forall v. Text -> v -> AProperty v
AProperty Text
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON GValue
v
instance FromGraphSON v => FromGraphSONWithKey (AVertexProperty v) where
parseGraphSONWithKey :: Text -> GValue -> Parser (AVertexProperty v)
parseGraphSONWithKey Text
k GValue
gv = case GValue -> GValueBody
gValueBody GValue
gv of
GObject KeyMap GValue
o -> forall v.
ElementID (AVertexProperty v) -> Text -> v -> AVertexProperty v
AVertexProperty
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (KeyMap GValue
o forall a. FromGraphSON a => KeyMap GValue -> Key -> Parser a
.: Key
"id")
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
k
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (KeyMap GValue
o forall a. FromGraphSON a => KeyMap GValue -> Key -> Parser a
.: Key
"value")
GValueBody
_ -> forall (f :: * -> *) a. Alternative f => f a
empty