Skip to content

Instantly share code, notes, and snippets.

@emaphp
Created April 10, 2019 22:41
Show Gist options
  • Select an option

  • Save emaphp/1f63e27d75bcd2de9b0476193e2b27cb to your computer and use it in GitHub Desktop.

Select an option

Save emaphp/1f63e27d75bcd2de9b0476193e2b27cb to your computer and use it in GitHub Desktop.
transform + reduce
function readPosX(stream, acc) {
let val = stream.substr(0, 2);
acc.posX = val;
return stream.substr(2);
}
function readPosY(stream, acc) {
let val = stream.substr(0, 2);
acc.posY = val;
return stream.substr(2);
}
var transformations = [readPosX, readPosY];
var stream = 'abcdef';
var data = {};
transformations.forEach(func => {
stream = func(stream, data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment