Funscript - Functional Typescript

This library facilitates functional programming practices by offering:
- recursive object cloning
- recursive object locking
- asynchronous versions of array functions
- compose utility to pipe multiple functions into one
These will aid in creating and working with immutable objects.
Clone
The Clone
function is straightforward: it recursively clones an object and returns the new object:
const newObj = Clone(oldObject);
console.log(oldObject === newObj);
If the object has its own clone
method, this function will utilize it. Otherwise, it will do a default recursive clone.
Lock
The Lock
function clones an object and freezes all properties on that clone, preventing any further mutation:
const newObj = Lock(oldObject);
console.log(oldObject === newObj);
try {
newObj.property = false;
} catch (err) {
}
FunAr
FunAr: functional asynchronous array, provides asynchronous versions of the common functional array methods in sequential and parallel flavors:
- Sequential
- map
- filter
- reduce
- find
- forEach (not technically functional but included for completeness)
- Parallel
- map
- filter
- forEach (not technically functional but included for completeness)
The sequential methods invoke the callback for each item one after another. The parallel methods invoke the callback for each item simultaneously.
const reduced = await FunAr.async.seq.reduce(inputArray, reduceFunction, initialValue);
const mapped = await FunAr.async.parallel.map(inputArray, (item, index) => return mapped);
Compose
Compose multiple functions and assign it to a single variable or execute immediately:
const compositeFunction = Compose(fOne, fTwo, fThree, fFour);
const result = compositeFunction(initialParam, otherParm);
const compositeAsyncFunction = ComposeAsync(fOneAsync, fTwoAsync, fThreeAsync);
const result = await compositeAsyncFunction(input);
const dynamicComposition = Compose(...arrayOfFunctions);
const result = dynamicComposition();