Skip to content

Instantly share code, notes, and snippets.

@ivan-nikitovic
Last active November 2, 2017 20:35
Show Gist options
  • Save ivan-nikitovic/ba2983f68b6c92a3a88aa4279074962f to your computer and use it in GitHub Desktop.
Save ivan-nikitovic/ba2983f68b6c92a3a88aa4279074962f to your computer and use it in GitHub Desktop.
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment