Skip to content

Instantly share code, notes, and snippets.

@neumino
Last active August 29, 2015 14:06
Show Gist options
  • Save neumino/94a310a4f82651ad5283 to your computer and use it in GitHub Desktop.
Save neumino/94a310a4f82651ad5283 to your computer and use it in GitHub Desktop.
    {
        "name": "John",
        "mark": 70,
        "id": 1,
        "course": "Mathematics"
    },
    {
        "name": "John",
        "mark": 90,
        "id": 2,
        "course": "English"
    }

Suppose we want to aggregate all John's marks in an object like

{
    Mathematics: 70,
    English: 90,
    ... // <course>: <mark>
}
r.table("marks").filter({student: "John"}).map(function(mark) {
    return r.object(mark("course"), mark("mark")) // return { mathematics: 70 }
}).reduce(function(left, right) {
    return left.merge(right);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment