Skip to content

Instantly share code, notes, and snippets.

View ivan-nikitovic's full-sized avatar

Ivan Nikitovic ivan-nikitovic

View GitHub Profile
@ivan-nikitovic
ivan-nikitovic / map.js
Last active November 2, 2017 20:35
Redux - Map array with conditional modification
const map = array => ({
when: condition => ({
then: modification => array.map(
(item, index, collection) => condition(item, index, collection) ? modification(item, index, collection) : item,
),
}),
});
map([1, 2, 3]).when(number => number > 1).then(number => number * 2) // [1, 4, 6]