1 | import { factory } from '../../utils/factory'
|
2 |
|
3 | const name = 'composition'
|
4 | const dependencies = [
|
5 | 'typed',
|
6 | 'addScalar',
|
7 | 'combinations',
|
8 | 'isNegative',
|
9 | 'isPositive',
|
10 | 'isInteger',
|
11 | 'larger'
|
12 | ]
|
13 |
|
14 | export const createComposition = factory(name, dependencies, (
|
15 | {
|
16 | typed,
|
17 | addScalar,
|
18 | combinations,
|
19 | isPositive,
|
20 | isNegative,
|
21 | isInteger,
|
22 | larger
|
23 | }
|
24 | ) => {
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | return typed(name, {
|
48 | 'number | BigNumber, number | BigNumber': function (n, k) {
|
49 | if (!isInteger(n) || !isPositive(n) || !isInteger(k) || !isPositive(k)) {
|
50 | throw new TypeError('Positive integer value expected in function composition')
|
51 | } else if (larger(k, n)) {
|
52 | throw new TypeError('k must be less than or equal to n in function composition')
|
53 | }
|
54 |
|
55 | return combinations(addScalar(n, -1), addScalar(k, -1))
|
56 | }
|
57 | })
|
58 | })
|