Skip to content

ReQL proposal: add the optional "base" argument back to .reduce() #3395

Closed

Description

@marshall007

Back before the new aggregation APIs were introduced, .groupedMapReduce() used to take an optional base argument that allowed you to set the initial reduction value. Since it's been removed, I find myself having to map over all the rows before the reduction. For example:

r.table('test')
.map(r.object(r.row('foo'), r.row('bar')))
.reduce(function (left, right) {
  return left.merge(right);
})
r.table('test')
.reduce(function (left, right) {
  return left.merge(r.object(right('foo'), right('bar')));
}, {})

Activity

  1. thelinuxlich commented on Dec 3, 2014

    @thelinuxlich

    +1 for this, very useful

  2. danielmewes commented on Dec 3, 2014

    @danielmewes
    Member

    Thanks for the suggestion @marshall007!
    We actually already have some discussion about it in #2629 . The running proposal is to have an if_empty opt arg to reduce (see #2629 (comment) ), which seems like it would work in your case.

    (closing as duplicate of #2629 )

  3. added this to the duplicate milestone on Dec 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions