Last active
February 3, 2019 19:17
-
-
Save Beraliv/4ec77011bde4fbad937057fb27a906db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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