mapreducejs
v1.0.1
Published
MapReduce using **socket.io**
Downloads
8
Readme
mapreduce.js
npm i mapreducejs --save
Node.js
let Master = require('mapreducejs/master');
let Agent = require('mapreducejs/agent');
Browser
<script src="agent.min.js"></script>
Master
let Master = require('mapreducejs/master');
// Supply an socket.io instance
let master = new Master(io);
...
// Connect to agent
// Returns a promise that resolves when finished connecting.
master.connect(socket);
master.source
Returns an iterable Dataset
.
let dataset = master.source([...]);
Dataset
dataset.data
Returns the actual data.
dataset.map
Perform a function on all entries in a list. Returns a promise that resolves the result Dataset
.
dataset.map((entry) => {
return ...
}).then((result) => {
...
});
dataset.reduce
Reduce a list into a single value context. Returns a promise that resolves the result Dataset
.
dataset.reduce((prev, next) => {
return ...
}).then((result) => {
...
});
Chaining
dataset.map((entry) => {
// Map
return ...
}).then((result) => {
// Reduce
result.reduce((prev, next) => {
return ...
}).then((result) => {
// Map
result.map((entry) => {
return ...
}).then((result) => {
let { data } = result;
});
});
});
Agent
let Agent = require('mapreducejs/agent');
// or <script src="agent.min.js"></script>
let agent = new Agent();
...
// Connect to master
// Supply an socket.io instance
// Returns a promise that resolves when finished connecting.
agent.connect(socket);