UNPKG

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