1.0.24 • Published 1 year ago

@dizmo/functions-partial v1.0.24

Weekly downloads
1
License
ISC
Repository
github
Last release
1 year ago

NPM version Build Status Coverage Status

@dizmo/functions-partial

Allows to bind any argument of a function using their names rather than their positions. This approach is more flexible if the initial arguments are to be left unbound. For example, from a function fn

fn(arg_0, arg_1, .., arg_[n-3], arg_[n-2], arg_[n-1])

we can create a new function gn, which requires all arguments but the last and the third last parameter by applying the

gn = fn.partial({arg_[n-3]: val_[n-3}, arg_[n-1]: val_[n-1]})

partial operation. The invocation of gn would look like gn(val_0, val_1, .., val_[n-2]). Notice that the relative position of the unbound arguments is left intact.

Usage

Install

npm install @dizmo/functions-partial --save

Require

const { partial } = require('@dizmo/functions-partial');

Examples

import { partial } from "@dizmo/functions-partial";
const add = (lhs: number, rhs: number): number => {
    return lhs + rhs;
};
const expect_inc = partial(add, {lhs: +1})(0) === +1;
const expect_dec = partial(add, {rhs: -1})(0) === -1;
const add = (lhs: number, rhs: number): number => {
    return lhs + rhs;
};
const inc = add.partial({lhs: +1});
const expect_inc = inc(0) === 1;
const nil = inc.partial({rhs: -1});
const expect_nil = nil( ) === 0;

Development

Clean

npm run clean

Build

npm run build

without linting and cleaning:

npm run -- build --no-lint --no-clean

with UMD bundling (incl. minimization):

npm run -- build --prepack

with UMD bundling (excl. minimization):

npm run -- build --prepack --no-minify

Lint

npm run lint

with auto-fixing:

npm run -- lint --fix

Test

npm run test

without linting, cleaning and (re-)building:

npm run -- test --no-lint --no-clean --no-build

Cover

npm run cover

without linting, cleaning and (re-)building:

npm run -- cover --no-lint --no-clean --no-build

Documentation

npm run docs

Publish

npm publish

initially (if public):

npm publish --access=public

Copyright

© 2020 dizmo AG, Switzerland

1.0.24

1 year ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago