Typed functional tools
Find a file
2019-09-22 23:05:33 +02:00
src tk-base upgrade 2019-09-22 23:05:33 +02:00
.editorconfig Added nop, identity, partial, cmp 2019-09-16 20:20:42 +02:00
.gitignore Added nop, identity, partial, cmp 2019-09-16 20:20:42 +02:00
.gitlab-ci.yml tk-base upgrade 2019-09-22 23:05:33 +02:00
activate_node Added nop, identity, partial, cmp 2019-09-16 20:20:42 +02:00
jest.config.js Added nop, identity, partial, cmp 2019-09-16 20:20:42 +02:00
package-lock.json tk-base upgrade 2019-09-22 23:05:33 +02:00
package.json tk-base upgrade 2019-09-22 23:05:33 +02:00
README.md tk-base upgrade 2019-09-22 23:05:33 +02:00
tsconfig.json tk-base upgrade 2019-09-22 23:05:33 +02:00

tk-functional

pipeline status coverage report npm version npm size

About

Provides some common helpers for functional-style programming.

Typescript definitions are included.

Issues can be reported on GitLab.

Functions

nop does nothing (useful for some callbacks):

new ConstructorWithMandatoryCallback(nop)

identity returns its argument untouched:

a === identity(a)  // => true

partial applies a partial configuration object as first argument of compatible functions:

const sum = (args: {a: number, b: number}) => args.a + args.b
const plus1 = partial({a: 1}, sum);
plus1({b: 8})  // => 9

cmp simplifies the use of array sorting:

[8, 3, 5].sort(cmp())                            // => [3, 5, 8]
[8, 3, 5].sort(cmp({ reverse: true }))           // => [8, 5, 3]
[-2, 8, -7].sort(cmp({ key: Math.abs }))         // => [-2, -7, 8]