UNPKG

1.21 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function chain
4
5Wrap any value in a chain, allowing to perform chained operations on
6the value.
7
8All methods available in the math.js library can be called upon the chain,
9and then will be evaluated with the value itself as first argument.
10The chain can be closed by executing `chain.done()`, which returns
11the final value.
12
13The chain has a number of special functions:
14
15- `done()` Finalize the chain and return the chain's value.
16- `valueOf()` The same as `done()`
17- `toString()` Executes `math.format()` onto the chain's value, returning
18 a string representation of the value.
19
20
21## Syntax
22
23```js
24math.chain(value)
25```
26
27### Parameters
28
29Parameter | Type | Description
30--------- | ---- | -----------
31`value` | * | A value of any type on which to start a chained operation.
32
33### Returns
34
35Type | Description
36---- | -----------
37math.Chain | The created chain
38
39
40## Examples
41
42```js
43math.chain(3)
44 .add(4)
45 .subtract(2)
46 .done() // 5
47
48math.chain( [[1, 2], [3, 4]] )
49 .subset(math.index(0, 0), 8)
50 .multiply(3)
51 .done() // [[24, 6], [9, 12]]
52```
53
54