Skip to content

Commit

Permalink
Greskell.GTraversal: add elementMap step
Browse files Browse the repository at this point in the history
  • Loading branch information
ners committed Nov 15, 2022
1 parent 1ce8608 commit a345c9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 16 additions & 4 deletions greskell/src/Data/Greskell/GTraversal.hs
Expand Up @@ -148,6 +148,7 @@ module Data.Greskell.GTraversal
, gId
, gLabel
, gValueMap
, gElementMap
, gSelect1
, gSelectN
, gSelectBy1
Expand Down Expand Up @@ -232,7 +233,7 @@ import Data.Greskell.AsLabel (AsLabel, LabeledP, SelectedMap)
import Data.Greskell.Graph (AEdge, AVertex, AVertexProperty, Cardinality, Edge,
Element (..), ElementID (..), Key, KeyValue (..),
Keys (..), Path, Property (..), T, Vertex, cList, tId,
(-:), (=:))
toGremlinKeys, (-:), (=:))
import Data.Greskell.GraphSON (FromGraphSON, GValue)
import Data.Greskell.Gremlin (Comparator (..), P, oDecr, oIncr, pBetween, pEq, pLte)
import Data.Greskell.Greskell (Greskell, ToGreskell (..), gvalueInt, toGremlin,
Expand Down Expand Up @@ -1391,9 +1392,14 @@ gValueMap :: Element s
=> Keys s
-> Walk Transform s (PMap (ElementPropertyContainer s) GValue)
gValueMap keys = unsafeWalk "valueMap" $ toGremlinKeys keys
where
toGremlinKeys KeysNil = []
toGremlinKeys (KeysCons k rest) = toGremlin k : toGremlinKeys rest

-- | @.elementMap@ step.
--
-- @since 2.0.0.1
gElementMap :: Element s
=> Keys s
-> Walk Transform s (PMap Single GValue)
gElementMap keys = unsafeWalk "elementMap" $ toGremlinKeys keys

-- | @.select@ step with one argument.
--
Expand Down Expand Up @@ -1819,6 +1825,12 @@ examples =
, ( toGremlin (source "g" & sV' [] &. gValueMap ("name" -: "age" -: KeysNil))
, "g.V().valueMap(\"name\",\"age\")"
)
, ( toGremlin (source "g" & sV' [] &. gElementMap KeysNil)
, "g.V().elementMap()"
)
, ( toGremlin (source "g" & sV' [] &. gElementMap ("name" -: "age" -: KeysNil))
, "g.V().elementMap(\"name\",\"age\")"
)
, ( let name_label = "a" :: AsLabel Text
name_key = "name" :: Key AVertex Text
count_label = "b" :: AsLabel Int
Expand Down
8 changes: 8 additions & 0 deletions greskell/src/Data/Greskell/Graph.hs
Expand Up @@ -44,6 +44,7 @@ module Data.Greskell.Graph
-- ** Heterogeneous list of keys
, Keys (..)
, singletonKeys
, toGremlinKeys
, (-:)
-- * Path
, Path (..)
Expand Down Expand Up @@ -298,6 +299,13 @@ instance Monoid (Keys a) where
singletonKeys :: Key a b -> Keys a
singletonKeys k = KeysCons k KeysNil

-- | Convert 'Keys' to a list of Gremlin scripts.
--
-- @since 2.0.0.1
toGremlinKeys :: Keys a -> [Text]
toGremlinKeys KeysNil = []
toGremlinKeys (KeysCons k rest) = toGremlin k : toGremlinKeys rest

-- | Prepend a 'Key' to 'Keys'.
--
-- @since 1.0.0.0
Expand Down

0 comments on commit a345c9d

Please sign in to comment.