Documentation available in : https://evanliomain.github.io/taninsam
A functionnal library based on a powerfull chain mecanism.
Yes you could just use simple ESNext functions to do your transformation. If you enjoy with it, just keep it that way.
But sometime, the code don't feel linear, so you are tempted to use a library. So why this one, instead of another ?
Taninsam is:
chain
a functionInstall taninsam:
npm install --save taninsam
or
yarn add taninsam
Import the librairie and start the chain:
import { chain, filter, map, sum } from 'taninsam';
// Sum square of even number in this collection
chain([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
.chain(filter(x => 0 === x % 2)) // [2, 4, 6, 8, 10]
.chain(map(x => x ** 2)) // [4, 16, 36, 64, 100]
.chain(sum()) // 220
.value();
To understand the chain function, it's as easy as this:
function chain(x) {
return {
chain: f => chain(f(x)),
value: () => x
};
}
So you can chain
as much as function you want, and called value()
at the end to get the actual value.
To extend the chain, it's as easy as to write a function:
import { chain } from 'taninsam';
chain(2)
.chain(x => x ** 2)
.chain(x => `square of 2 is ${x}`)
.value(); // 'square of 2 is 4'
yarn
Main commands to develop
yarn gen
: Create a new functionyarn test:watch
: Run test suite in interactive watch modeyarn commit
: Commit using conventional commit styleAdditionals commands
yarn lint
: Lints codeyarn test
: Run test suite onceyarn stryker
: Run mutation testing suite onceyarn build
: Generate bundles and typings, create docsyarn start
: Runs npm run build
in watch modeCode source is automatically formatted and linted at each commit.
This library was bootstraped by typescript-library-starter.