How can I write a project using an inject that doesn't exhaust itself?
Take the following example query:
g.inject("1", "2", "3").project("list").by(__.inject("b").fold()).toList()
its result is [{list=[1, b]}, {list=[2]}, {list=[3]}]
I'd like to see [{list=[1, b]}, {list=[2, b]}, {list=[3, b]}] instead
How can I accomplish this?
4 Replies
have you try :
g.inject("1", "2", "3").project("list").by(__.union(identity(),constant("b")).fold()).toList()
+1 to
constant()
in this case.Thanks, I saw that at your blog post https://stephen.genoprime.com/snippet/2020/02/15/snippet-2.html
stephen mallette
constant() Is Not inject()
The constant() step looks a bit like inject(). Both look like they take some arbitrary “constant” sort of value and “inject” it into the traversal stream.
I'll try again with this pattern
Thanks, I was able to get my issue sorted out with this pattern!