https://github.com/smart-table/smart-table-operators
functional operators for smart table and friends
https://github.com/smart-table/smart-table-operators
browser functional grid smart-table table
Last synced: 9 months ago
JSON representation
functional operators for smart table and friends
- Host: GitHub
- URL: https://github.com/smart-table/smart-table-operators
- Owner: smart-table
- License: mit
- Created: 2017-02-01T16:09:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T17:43:07.000Z (over 3 years ago)
- Last Synced: 2025-09-18T19:24:35.947Z (9 months ago)
- Topics: browser, functional, grid, smart-table, table
- Language: JavaScript
- Size: 197 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# smart-table-operators
[](https://circleci.com/gh/smart-table/smart-table-operators)
A basic set of functional operators (or higher order function) for nodejs and browsers. Used internally in [smart-table]('https://github.com/smart-table/smart-table-core') but can be useful to anyone. However if you need something more elaborated you'll probably be more interested in
[Ramda](https://github.com/ramda/ramda) or [lodash](https://github.com/lodash/lodash)
## Installation
### npm
``npm install smart-table-operators --save``
### yarn
``yarn add smart-table-operators``
## Usage
### swap
Swap arguments, returning a new function.
```Javascript
import {swap} from 'smart-table-operators';
const substract = (a,b) => a-b;
const f = swap(substract);
substract(4,2);
// > 2
f(4,2);
// > -2
```
### compose
compose function returning a new function.
```Javascript
import {compose} from 'smart-table-operators';
const addTwo = (a) => a + 2;
const multiplyByThree = (a) => a * 3;
const addTwoTimesThree = compose(addTow, multiplyByThree);
addTwoTimesThree(4);
// > 18
```
### tap
call side effects, returning a new function (which returns the initial argument).
```Javascript
import {tap} from 'smart-table-operators';
const log = tap((a)=>console.log(a));
const four = log(4);
// > 4
console.log(four)
// > 4
```
### curry
Takes a function and return a new function. If this new function is called whereas the argument length is not equal to the arity, returns a new function.
```Javascript
import {curry} from 'smart-table-operators'
const curriedAdd = curry((a,b) => a + b);
curriedAdd(2,3);
// > 5
const addTwo = curriedAdd(2);
addTow(3);
// > 5
```
You can specify the expected arity (useful when passing default value)
```Javascript
import {curry} from 'smart-table-operators';
const add = function (a, b=2){return a+b;};
const curriedAdd = curry(add,2);
const addThree = curriedAdd(3);
addThree();
// > 5
```
## Contributing
### test
``npm test``
or
``yarn test``
### issues
Only **bugs** coming with a **running example**