[ 
https://issues.apache.org/jira/browse/TINKERPOP3-761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14715813#comment-14715813
 ] 

Matt Frantz commented on TINKERPOP3-761:
----------------------------------------

You could either make {{Operator}} go away by adding lots of new math steps, or 
make the math steps go away by adding a single step which takes an {{Operator}} 
argument.  I personally favor the latter, since it avoids splatting the math 
steps into the {{GraphTraversal}} API.

Consider a new n-ary functor step, e.g. {{curry}}.  If given a binary function 
argument, it would accept one or two placement arguments (which would be 
traversals).  If only one placement argument is provided, then it fulfills the 
binary function requirement with the traverser value.

{noformat}
 ...curry(Operator.add, select('a'), select('b'))  // Add a and b
 ...curry(Operator.add, select('a'))  // Add a to the traverser
{noformat}

If we want {{Operator.add}} to be n-ary, we could do that, and allow more 
placement arguments.  But it might be hard to decide whether to include the 
traverser.

{noformat}
 ...curry(Operator.add, select('a'), select('b'), select('c'))  // Add a, b, 
and c, but not the traverser?
{noformat}

If we want to apply {{Scoping}} logic, then you could use {{fold}} as-is (by 
passing an {{Operator}} for the optional reducer).

This would be consistent with the proposed use case in TINKERPOP3-788.

If we want to use {{Parameters}}, then you need a clause like {{by}}.

{noformat}
...curry(Operator.add).by(select('a'))  // Add a to the traverser
...curry(Operator.add).by(select('a')).by(select('b'))  // Add a and b together
{noformat}

With {{by}}, you could decide where the traverser goes in a function that is 
not commutative.

{noformat}
...curry(Operator.divide).by(select('a'))  // Divide 'a' by the traverser
...curry(Operator.divide).by().by(select('a'))  // Divide the traverser by 'a'
{noformat}

Of course, you could do the above using placement arguments by using the 
{{identity}} step.

{noformat}
...curry(Operator.divide, select('a'))  // Divide 'a' by the traverser
...curry(Operator.divide, identity(), select('a'))  // Divide the traverser by 
'a'
{noformat}


> Some basic mathematical functions / steps
> -----------------------------------------
>
>                 Key: TINKERPOP3-761
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP3-761
>             Project: TinkerPop 3
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 3.0.0-incubating
>            Reporter: Daniel Kuppitz
>            Assignee: Marko A. Rodriguez
>
> Every once in a while I wish to have steps for some basic mathematical 
> operations ({{add()}}, {{sub()}}, {{mul()}}, {{div()}}). Since {{sub(num)}} 
> is the same as {{add(-num)}} and {{div(num)}} is the same as {{mul(1/num)}}, 
> we would only need two new step implementations.
> Oh, and then there's also {{mod()}}, thus 3 new step implementations.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to