Skip to content

Instantly share code, notes, and snippets.

@Beraliv
Last active February 3, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Beraliv/4ec77011bde4fbad937057fb27a906db to your computer and use it in GitHub Desktop.
Save Beraliv/4ec77011bde4fbad937057fb27a906db to your computer and use it in GitHub Desktop.
import { add, filterT, mapT, pipeT, transduce } from 'nanoutils';
const isEven = value => value % 2 === 0;
const transducers = array => {
const transducer = pipeT(
// transforms value to value + 1
mapT(add(1)),
// ignores odd values
filterT(isEven),
);
// iterates over values + 1 which are not odd
// applies add
// starts from 0
// gets values from array
return transduce(transducer, add, 0, array);
}
const ages = [16, 23, 24]
transducers(ages) // 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment