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
Flynnt
Flynnt2y ago
have you try : g.inject("1", "2", "3").project("list").by(__.union(identity(),constant("b")).fold()).toList()
spmallette
spmallette2y ago
+1 to constant() in this case.
danielcraig23
danielcraig23OP2y ago
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.
danielcraig23
danielcraig23OP2y ago
I'll try again with this pattern Thanks, I was able to get my issue sorted out with this pattern!

Did you find this page helpful?