1 | import { factory } from '../../../utils/factory.js';
|
2 | var name = 'chain';
|
3 | var dependencies = ['typed', 'Chain'];
|
4 | export var createChain = /* #__PURE__ */factory(name, dependencies, (_ref) => {
|
5 | var {
|
6 | typed,
|
7 | Chain
|
8 | } = _ref;
|
9 |
|
10 | /**
|
11 | * Wrap any value in a chain, allowing to perform chained operations on
|
12 | * the value.
|
13 | *
|
14 | * All methods available in the math.js library can be called upon the chain,
|
15 | * and then will be evaluated with the value itself as first argument.
|
16 | * The chain can be closed by executing `chain.done()`, which returns
|
17 | * the final value.
|
18 | *
|
19 | * The chain has a number of special functions:
|
20 | *
|
21 | * - `done()` Finalize the chain and return the chain's value.
|
22 | * - `valueOf()` The same as `done()`
|
23 | * - `toString()` Executes `math.format()` onto the chain's value, returning
|
24 | * a string representation of the value.
|
25 | *
|
26 | * Syntax:
|
27 | *
|
28 | * math.chain(value)
|
29 | *
|
30 | * Examples:
|
31 | *
|
32 | * math.chain(3)
|
33 | * .add(4)
|
34 | * .subtract(2)
|
35 | * .done() // 5
|
36 | *
|
37 | * math.chain( [[1, 2], [3, 4]] )
|
38 | * .subset(math.index(0, 0), 8)
|
39 | * .multiply(3)
|
40 | * .done() // [[24, 6], [9, 12]]
|
41 | *
|
42 | * @param {*} [value] A value of any type on which to start a chained operation.
|
43 | * @return {math.Chain} The created chain
|
44 | */
|
45 | return typed(name, {
|
46 | '': function _() {
|
47 | return new Chain();
|
48 | },
|
49 | any: function any(value) {
|
50 | return new Chain(value);
|
51 | }
|
52 | });
|
53 | }); |
\ | No newline at end of file |