evanliomain / taninsam

A functionnal library based on a powerfull chain mecanism.
https://evanliomain.github.io/taninsam
MIT License
5 stars 1 forks source link
functionnal-library taninsam tdd transformations typescript

Taninsam

Documentation available in : https://evanliomain.github.io/taninsam

A functionnal library based on a powerfull chain mecanism.

Release Coveralls

styled with prettier Made with Commitizen friendly semantic-release

npm npm bundle size npm bundle size npm npm

npm

Why should I use Taninsam ?

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:

Getting started

Install 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'

Contributing

Installation

yarn

Coding

Main commands to develop

Additionals commands

Code source is automatically formatted and linted at each commit.

This library was bootstraped by typescript-library-starter.