Skip to content

Instantly share code, notes, and snippets.

@mfrachet
Created January 15, 2019 14:45
Show Gist options
  • Save mfrachet/a91fc4d61c78d5cc5b87552b0d963768 to your computer and use it in GitHub Desktop.
Save mfrachet/a91fc4d61c78d5cc5b87552b0d963768 to your computer and use it in GitHub Desktop.
ningo-transduce.js
import transduce from "ningo/transduce";
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const isEven = x => x % 2 === 0;
const double = x => x * 2;
const doubleEven = transduce()
.map(double) // runs second
.filter(isEven); // runs first
const newArray = doubleEven.run(data);
console.log(newArray); // [ 4, 8, 12, 16, 20 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment