Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Seamless Immutable | 5,280 | 3,469 | 501 | 2 years ago | 53 | August 31, 2018 | 55 | bsd-3-clause | JavaScript | |
Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects. | ||||||||||
Immer | 2,201 | 25 days ago | 42 | bsl-1.0 | C++ | |||||
Postmodern immutable and persistent data structures for C++ — value semantics at scale | ||||||||||
Pyrsistent | 1,797 | 1,722 | 358 | 3 months ago | 71 | January 14, 2022 | 18 | mit | Python | |
Persistent/Immutable/Functional data structures for Python | ||||||||||
List | 1,638 | 53 | 18 | a month ago | 33 | October 09, 2019 | 23 | mit | TypeScript | |
🐆 An immutable list with unmatched performance and a comprehensive functional API. | ||||||||||
Bifurcan | 912 | 1 | 6 months ago | 12 | May 15, 2021 | 11 | mit | Java | ||
functional, durable data structures | ||||||||||
Ecmascript Immutable Data Structures | 579 | 6 years ago | 15 | |||||||
Ewig | 480 | 7 months ago | 1 | gpl-3.0 | C++ | |||||
The eternal text editor — Didactic Ersatz Emacs to show immutable data-structures and the single-atom architecture | ||||||||||
Data Structures | 377 | 6 | 37 | 8 months ago | 6 | July 18, 2022 | 1 | other | Go | |
Go datastructures. | ||||||||||
Prelude Ts | 364 | 2 | 8 | a month ago | 8 | May 27, 2022 | 16 | isc | TypeScript | |
Functional programming, immutable collections and FP constructs for typescript and javascript | ||||||||||
Static Frame | 339 | 2 | 3 days ago | 158 | July 01, 2022 | 38 | other | Python | ||
Immutable and grow-only Pandas-like DataFrames with a more explicit and consistent interface. |
Immunity is a set of helper methods in order to construct a new version of data without mutating/updating existing data structure in-place.
Compared to its alternatives, immunity only provides utility functions instead of delivering new data types/structures as a solution.
Additionally, as a library, Immunity is completely tree-shaking-friendly. Your favorite module bundler can easily inline the functionality you need with no extra configuration, instead of bundling the whole Immunity package.
Execute npm install immunity
or yarn add immunity
to install immunity and its dependencies into your project directory.
appends new item(s) to an array or a generator.
import appendToArray from 'immunity/appendToArray';
const source = [ 'a', 'b' ];
const newOne = appendToArray(source, 'c');
// output: Result: ['a','b','c']
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
appends new item(s) to an object.
import appendToObject from 'immunity/appendToObject';
const source = { a: 1, b: 2 };
const newOne = appendToObject(source, { c: 3 });
// output: Result: {'a':1,'b':2,'c':3}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
copies an instance with its constructor.
import copy from 'immunity/copy';
class dummy {}
const source = new dummy();
const newOne = copy(source);
// output: Result: class dummy {}
console.log('Result:', newOne.constructor);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
skips first n items from an array or a generator.
import dropFromArray from 'immunity/dropFromArray';
const source = [ 'a', 'b', 'c' ];
const newOne = dropFromArray(source, 1);
// output: Result: ['b','c']
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
skips first n items from an object.
import dropFromObject from 'immunity/dropFromObject';
const source = { a: 1, b: 2, c: 3 };
const newOne = dropFromObject(source, 1);
// output: Result: {'b':2,'c':3}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
returns matching items from an array or a generator.
import filterArray from 'immunity/filterArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = filterArray(source, x => x <= 3);
// output: Result: [1,2,3]
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
returns matching items from an object.
import filterObject from 'immunity/filterObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = filterObject(source, x => x <= 3);
// output: Result: {'a':1,'b':2,'c':3}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
creates a new array with the results of calling a provided function on every element in the calling array.
import mapArray from 'immunity/mapArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = mapArray(source, x => x - 1);
// output: Result: [0,1,2,3,4]
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
creates a new object with the results of calling a provided function on every element in the calling object.
import mapObject from 'immunity/mapObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = mapObject(source, (value, key) => ({ [key]: value - 1 }));
// output: Result: {'a':0,'b':1,'c':2,'d':3,'e':4}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
merges two or more arrays into one.
import mergeArrays from 'immunity/mergeArrays';
const source1 = [ 1, 2, 3 ];
const source2 = [ 4, 5 ];
const newOne = mergeArrays(source1, source2);
// output: Result: [1,2,3,4,5]
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
merges two or more objects into one.
import mergeObjects from 'immunity/mergeObjects';
const source1 = { a: 1, b: 2, c: 3 };
const source2 = { d: 4, e: 5 };
const newOne = mergeObjects(source1, source2);
// output: Result: {'a':1,'b':2,'c':3,'d':4,'e':5}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
returns matching and not matching items from an array or a generator.
import pickFromArray from 'immunity/pickFromArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = pickFromArray(source, [ 2, 3, 6 ]);
// output: Result: {'items':[2,3],'rest':[1,4,5]}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
returns matching and not matching items from an object.
import pickFromObject from 'immunity/pickFromObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = pickFromObject(source, [ 'b', 'c', 'f' ]);
// output: Result: {'items':{'b':2,'c':3},'rest':{'a':1,'d':4,'e':5}}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
prepends new item(s) to an array or a generator.
import prependToArray from 'immunity/prependToArray';
const source = [ 'b', 'c' ];
const newOne = prependToArray(source, 'a');
// output: Result: ['a','b','c']
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
prepends new item(s) to an object.
import prependToObject from 'immunity/prependToObject';
const source = { b: 2, c: 3 };
const newOne = prependToObject(source, { a: 1 });
// output: Result: {'a':1,'b':2,'c':3}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
removes first matching item from an array or a generator.
import removeFirstMatchFromArray from 'immunity/removeFirstMatchFromArray';
const source = [ 1, 5, 2, 3, 4, 5 ];
const newOne = removeFirstMatchFromArray(source, x => x === 5);
// output: Result: [1,2,3,4,5]
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
removes first matching item from an object.
import removeFirstMatchFromObject from 'immunity/removeFirstMatchFromObject';
const source = { a: 1, f: 5, b: 2, c: 3, d: 4, e: 5 };
const newOne = removeFirstMatchFromObject(source, x => x === 5);
// output: Result: {'a':1,'b':2,'c':3,'d':4,'e':5}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
removes specified item(s) from an array or a generator.
import removeFromArray from 'immunity/removeFromArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = removeFromArray(source, 2, 3);
// output: Result: [1,4,5]
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
removes items with specified key(s) from an object.
import removeKeyFromObject from 'immunity/removeKeyFromObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = removeKeyFromObject(source, 'b', 'c');
// output: Result: {'a':1,'d':4,'e':5}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
removes items with specified value(s) from an object or a generator.
import removeValueFromObject from 'immunity/removeValueFromObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = removeValueFromObject(source, 2, 3);
// output: Result: {'a':1,'d':4,'e':5}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
reverses an array or a generator content.
import reverseArray from 'immunity/reverseArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = reverseArray(source);
// output: Result: [5,4,3,2,1]
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
reverses an object content.
import reverseObject from 'immunity/reverseObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = reverseObject(source);
// output: Result: {'e':5,'d':4,'c':3,'b':2,'a':1}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
splits an array or a generator content from specified index.
import splitArray from 'immunity/splitArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = splitArray(source, 3);
// output: Result: {'items':[1,2,3],'rest':[4,5]}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
splits an array or a generator content from specified last index.
import splitLastArray from 'immunity/splitLastArray';
const source = [ 1, 2, 3, 4, 5 ];
const newOne = splitLastArray(source, 2);
// output: Result: {'items':[4,5],'rest':[1,2,3]}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
splits an object content from specified index.
import splitObject from 'immunity/splitObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = splitObject(source, 3);
// output: Result: {'items':{'a':1,'b':2,'c':3},'rest':{'d':4,'e':5}}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
splits an object content from specified last index.
import splitLastObject from 'immunity/splitLastObject';
const source = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const newOne = splitLastObject(source, 2);
// output: Result: {'items':{'d':4,'e':5},'rest':{'a':1,'b':2,'c':3}}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
takes first n items from an array or a generator.
import takeFromArray from 'immunity/takeFromArray';
const source = [ 'a', 'b', 'c' ];
const newOne = takeFromArray(source, 2);
// output: Result: ['a','b']
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
takes first n items from an object.
import takeFromObject from 'immunity/takeFromObject';
const source = { a: 1, b: 2, c: 3 };
const newOne = takeFromObject(source, 2);
// output: Result: {'a':1,'b':2}
console.log(`Result: ${JSON.stringify(newOne)}`);
// output: Is Same: false
console.log(`Is Same: ${source === newOne}`);
See GitHub Projects for more.
Apache 2.0, for further details, please see LICENSE file
See contributors.md
It is publicly open for any contribution. Bugfixes, new features and extra modules are welcome.