Skip to content

Instantly share code, notes, and snippets.

@dlmanning
Last active Jan 13, 2016
Embed
What would you like to do?
tiny little transducer util made with universal-reduce
import reduce from 'universal-reduce'
const transduce = (put, initial) => (collection, ...xfs) =>
reduce(collection, (accum, value, key) =>
put(
accum,
key,
reduce(xfs, (result, xf) => xf(result), value)
),
initial
)
// example
const mapObjectValuesIntoSet = transduce((set, value) => set.add(value), new Set())
mapObectValuesIntoSet({
book1: 'Tale of Two Cities',
book2: 'Anathem',
book3: 'Saved By The Bell: The Inside Story'
}, str => str.toLowerCase())
// returns
// Set { 'tale of two cities', 'anathem', 'saved by the bell: the inside story' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment