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
Flynnt16mo ago
have you try : g.inject("1", "2", "3").project("list").by(__.union(identity(),constant("b")).fold()).toList()
spmallette
spmallette16mo ago
+1 to constant() in this case.
danielcraig23
danielcraig2316mo 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
danielcraig2316mo ago
I'll try again with this pattern Thanks, I was able to get my issue sorted out with this pattern!
Want results from more Discord servers?
Add your server