Last active
September 19, 2017 10:43
-
-
Save gabrielhpugliese/a7a85942735e980d4f8f1414c7e5272e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
compose, | |
findIndex, | |
cond, | |
} from 'lodash/fp'; | |
const MY_LIST = [/* items here */]; | |
const findMyItemIndex = findIndex(item => item === 'MY_ITEM'); | |
const changeItemToSomething = () => // returns NEW object (immutable) | |
const doMagic = (item, list) => compose( | |
cond([ | |
[(index) => index === -1, () => list], | |
[(index) => index > -1, (index) => changeItemToSomething(item, list)], | |
]), | |
findMyItemIndex(item), | |
)(list); | |
doMagic({a: 1}, MY_LIST); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment