From 85f9882590f025963591c8bc437cecf6c5221392 Mon Sep 17 00:00:00 2001 From: ners Date: Wed, 16 Nov 2022 13:46:57 +0100 Subject: [PATCH] Bump version to 2.0.1.0, add elementMap step --- greskell/ChangeLog.md | 3 ++- greskell/greskell.cabal | 2 +- greskell/src/Data/Greskell/GTraversal.hs | 20 ++++++++++++++++---- greskell/src/Data/Greskell/Graph.hs | 8 ++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/greskell/ChangeLog.md b/greskell/ChangeLog.md index dcc1536..9cab64e 100644 --- a/greskell/ChangeLog.md +++ b/greskell/ChangeLog.md @@ -1,10 +1,11 @@ # Revision history for greskell -## 2.0.0.1 -- ? +## 2.0.1.0 * Confirm test with ghc-9.2.1. * Remove doctests. This was because it's become more and more difficult to run doctests in a cabal package. * @ners helped a lot in https://github.com/debug-ito/greskell/pull/12 +* Add the `gElementMap` function. ## 2.0.0.0 -- 2021-12-28 diff --git a/greskell/greskell.cabal b/greskell/greskell.cabal index 6538de3..67d1316 100644 --- a/greskell/greskell.cabal +++ b/greskell/greskell.cabal @@ -1,5 +1,5 @@ name: greskell -version: 2.0.0.1 +version: 2.0.1.0 author: Toshio Ito maintainer: Toshio Ito license: BSD3 diff --git a/greskell/src/Data/Greskell/GTraversal.hs b/greskell/src/Data/Greskell/GTraversal.hs index 473e8ee..10dce74 100644 --- a/greskell/src/Data/Greskell/GTraversal.hs +++ b/greskell/src/Data/Greskell/GTraversal.hs @@ -148,6 +148,7 @@ module Data.Greskell.GTraversal , gId , gLabel , gValueMap + , gElementMap , gSelect1 , gSelectN , gSelectBy1 @@ -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, @@ -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.1.0 +gElementMap :: Element s + => Keys s + -> Walk Transform s (PMap Single GValue) +gElementMap keys = unsafeWalk "elementMap" $ toGremlinKeys keys -- | @.select@ step with one argument. -- @@ -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 diff --git a/greskell/src/Data/Greskell/Graph.hs b/greskell/src/Data/Greskell/Graph.hs index 0698f0f..d5fd69b 100644 --- a/greskell/src/Data/Greskell/Graph.hs +++ b/greskell/src/Data/Greskell/Graph.hs @@ -44,6 +44,7 @@ module Data.Greskell.Graph -- ** Heterogeneous list of keys , Keys (..) , singletonKeys + , toGremlinKeys , (-:) -- * Path , Path (..) @@ -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.1.0 +toGremlinKeys :: Keys a -> [Text] +toGremlinKeys KeysNil = [] +toGremlinKeys (KeysCons k rest) = toGremlin k : toGremlinKeys rest + -- | Prepend a 'Key' to 'Keys'. -- -- @since 1.0.0.0