UNPKG

517 BJavaScriptView Raw
1#!/usr/bin/env node
2
3var sc = require('skale-engine').context();
4
5function reducer(a, b) {a.push(b); return a;}
6function combiner(a, b) {return a.concat(b);}
7
8function by2(a) {return a * 2;}
9
10sc.parallelize([['hello', 1], ['world', 2], ['cedric', 3], ['test', 4]])
11 .mapValues(by2)
12 .aggregate(reducer, combiner, [], function(err, res) {
13 console.log(res);
14 res.sort();
15 console.assert(JSON.stringify(res) === JSON.stringify([['cedric', 6], ['hello', 2], ['test', 8], ['world', 4]]));
16 sc.end();
17 });