1 | #!/usr/bin/env node
|
2 |
|
3 | var sc = require('skale-engine').context();
|
4 |
|
5 | function reducer(a, b) {a.push(b); return a;}
|
6 | function combiner(a, b) {return a.concat(b);}
|
7 |
|
8 | function by2(a) {return a * 2;}
|
9 |
|
10 | sc.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 | });
|