# tinkerpop-dev mailing list archives

##### Site index · List index
Message view
Top
From "Matt Frantz (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TINKERPOP3-761) Some basic mathematical functions / steps
Date Mon, 03 Aug 2015 15:07:05 GMT
```
[ https://issues.apache.org/jira/browse/TINKERPOP3-761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14651960#comment-14651960
]

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

Instead of a family of steps, we could have a single {{reduce}} step with an enumerated set
of operations, {{R}}, much as {{P}} provides an enumerated set of predicates.  It could have
{{Scoping}} implementations, so that it could apply as a reducing barrier step (global) or
as a map operation on a {{List}} (local).

{noformat}
g.V().values('age').reduce(R.average).as('averageAge')
g.V().values('age').fold().reduce(R.average).as('averageAge')
g.V().values('age').reduce(R.histogram).as('ageHisto')
{noformat}

(Incidentally, this allows the {{fold}} step to be expressed as {{reduce(R.list)}}.)

You could optionally seed the reduce:
{noformat}
{noformat}

You could also have a single {{bind}} step (in the family of {{map}}) that would apply the
binary {{R}} operator with a constant bound to either operand:
{noformat}
g.V().values('age').bind(2, R.divide).as('twoDividedByAge')
g.V().values('age').bind(R.divide, 2).as('ageDividedByTwo')
{noformat}

We could interpret string arguments to {{bind}} or {{reduce}} to be labels/keys that can be
{{select}}ed, and {{by}}ed:
{noformat}
g.V().as('a').out('knows').as('b')
{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)

```
Mime
View raw message