I'm using a functional library (Gremlin) to query a graph database. Invoking it looks like this:
g.V().has(...).out(...).hasLabel(...).in(...).next();
Some of my functional chains are very long, and I'd like to be able to reuse pieces of them for DRY purposes. For example:
const postProjection = () => (
project("id", "title")
.by(__.id())
.by("title")
)
g.V().hasLabel("post").postProjection().next()
I know this doesn't work but that is the concept. I want to encapsulate a piece of this chain into a function that I can (somehow) inject into various other function chains from this library where needed. By dynamically constructing these calls with reusable segments I could dramatically cut down on repetition.
Is this possible to do?