@dizmo/functions-partial v1.0.24
@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 --saveRequire
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 cleanBuild
npm run buildwithout linting and cleaning:
npm run -- build --no-lint --no-cleanwith UMD bundling (incl. minimization):
npm run -- build --prepackwith UMD bundling (excl. minimization):
npm run -- build --prepack --no-minifyLint
npm run lintwith auto-fixing:
npm run -- lint --fixTest
npm run testwithout linting, cleaning and (re-)building:
npm run -- test --no-lint --no-clean --no-buildCover
npm run coverwithout linting, cleaning and (re-)building:
npm run -- cover --no-lint --no-clean --no-buildDocumentation
npm run docsPublish
npm publishinitially (if public):
npm publish --access=publicCopyright
© 2020 dizmo AG, Switzerland
3 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago