Skip to content

Instantly share code, notes, and snippets.

@gabrielhpugliese
Created September 19, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielhpugliese/d9f12294d7eb14e57d0cd6e39a643462 to your computer and use it in GitHub Desktop.
Save gabrielhpugliese/d9f12294d7eb14e57d0cd6e39a643462 to your computer and use it in GitHub Desktop.
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) => {
const index = findMyItemIndex(item);
return index > -1
&& changeItemToSomething(item, list)
|| list;
};
doMagic({a: 1}, MY_LIST);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment