Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robertherber/find-and-replace-immutable
Exposes immutable findAndReplace and replaceAt functions on top of lodash/fp
https://github.com/robertherber/find-and-replace-immutable
immutable javascript node utility
Last synced: 2 months ago
JSON representation
Exposes immutable findAndReplace and replaceAt functions on top of lodash/fp
- Host: GitHub
- URL: https://github.com/robertherber/find-and-replace-immutable
- Owner: robertherber
- Created: 2017-06-20T05:15:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-20T05:44:03.000Z (over 7 years ago)
- Last Synced: 2024-10-23T01:32:43.340Z (2 months ago)
- Topics: immutable, javascript, node, utility
- Language: JavaScript
- Size: 46.9 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# find-and-replace-immutable
Exposes two simple but essential helper immutable methods:
* replaceAt (index, objectOrMapFunction, array)
* findAndReplace (findPredicateFunction, objectOrMapFunction, array)Uses [lodash/fp](https://github.com/lodash/lodash/wiki/FP-Guide) under the hood, which is great for it's immutability.
I always end up using this in my React projects - so I thought I'd share it! ;)
## Examples
Using *replaceAt*:
~~~~
import { replaceAt } from 'find-and-replace-immutable';const initialArray = ["original"];
const newArray = replaceAt(0, "new value", initialArray);
// expect(newArray).toEqual(["new value"]);
// expect(initialArray).toEqual(["original"]);
~~~~Using *findAndReplace* with mapping function:
~~~~
import { findAndReplace } from 'find-and-replace-immutable';const initialArray = [1, 2, 3, 3, 4, 5];
const newArray = findAndReplace(
e => e === 3,
oldValue => 33 * oldValue,
initialArray
);// expect(newArray).toEqual([1, 2, 99, 3, 4, 5]);
~~~~