ziko 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +396 -117
- package/dist/ziko.js +396 -117
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +369 -118
- package/package.json +1 -1
- package/src/dom/components/for/index.js +17 -0
- package/src/dom/components/index.js +2 -1
- package/src/dom/components/swap/index.js +3 -3
- package/src/dom/constructors/UIElement.js +23 -4
- package/src/dom/constructors/UIElementCore.js +2 -1
- package/src/dom/constructors/mixins/dom.js +31 -22
- package/src/math/complex/index.d.ts +207 -30
- package/src/math/functions/arithmetic/index.d.ts +95 -0
- package/src/math/functions/conversions/index.d.ts +101 -0
- package/src/math/functions/index.d.ts +97 -90
- package/src/math/functions/logic/index.d.ts +50 -8
- package/src/math/functions/logic/index.js +1 -1
- package/src/math/functions/mapfun/index.d.ts +46 -80
- package/src/math/functions/mapfun/index.d.ts.txt +162 -0
- package/src/math/functions/signal/index.d.ts +146 -0
- package/src/math/functions/stats/index.js +33 -33
- package/src/math/functions/ufunc/index.d.ts +96 -0
- package/src/math/functions/utils/index.d.ts +118 -1
- package/src/math/index.d.ts +4 -0
- package/src/math/index.js +1 -16
- package/src/math/random/index.d.ts +162 -0
- package/src/math/random/index.js +4 -4
- package/src/math/stats/accum/index.d.ts +43 -0
- package/src/math/stats/average/index.d.ts +123 -0
- package/src/math/stats/index.d.ts +5 -0
- package/src/math/stats/percentile/index.d.ts +66 -0
- package/src/math/stats/rolling/index.d.ts +47 -0
- package/src/math/stats/variability/index.d.ts +93 -0
- package/src/math/index.d.ts.txt +0 -5
|
@@ -1,140 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export type * from './arithmetic/index.d.ts'
|
|
2
|
+
export type * from './conversions/index.d.ts'
|
|
3
|
+
export type * from './logic/index.d.ts'
|
|
4
|
+
export type * from './utils/index.d.ts'
|
|
5
|
+
export type * from './mapfun/index.d.ts'
|
|
6
|
+
export type * from './ufunc/index.d.ts'
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
// import type { Complex } from "../complex/index.js";
|
|
9
|
+
// import type { MapfunResult, Mappable } from "../utils/mapfun.js";
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
A["length"] extends 1
|
|
8
|
-
? MapfunResult<F, A[0]>
|
|
9
|
-
: { [K in keyof A]: MapfunResult<F, A[K]> };
|
|
11
|
+
// /* -------------------- MapfunWrap -------------------- */
|
|
10
12
|
|
|
13
|
+
// type MapfunWrap<F extends (x: any) => any, A extends Mappable[]> =
|
|
14
|
+
// A["length"] extends 1
|
|
15
|
+
// ? MapfunResult<F, A[0]>
|
|
16
|
+
// : { [K in keyof A]: MapfunResult<F, A[K]> };
|
|
11
17
|
|
|
12
|
-
/* -------------------- mapfun-based simple operators -------------------- */
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
MapfunWrap<typeof Math.abs, A>;
|
|
19
|
+
// /* -------------------- mapfun-based simple operators -------------------- */
|
|
16
20
|
|
|
17
|
-
export declare function
|
|
18
|
-
|
|
21
|
+
// export declare function abs<A extends Mappable[]>(...x: A):
|
|
22
|
+
// MapfunWrap<typeof Math.abs, A>;
|
|
19
23
|
|
|
20
|
-
export declare function
|
|
21
|
-
|
|
24
|
+
// export declare function sqrt<A extends Mappable[]>(...x: A):
|
|
25
|
+
// MapfunWrap<typeof Math.sqrt, A>;
|
|
22
26
|
|
|
23
|
-
export declare function
|
|
24
|
-
|
|
27
|
+
// export declare function e<A extends Mappable[]>(...x: A):
|
|
28
|
+
// MapfunWrap<typeof Math.exp, A>;
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
// export declare function ln<A extends Mappable[]>(...x: A):
|
|
31
|
+
// MapfunWrap<typeof Math.log, A>;
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
MapfunWrap<typeof Math.cos, A>;
|
|
33
|
+
// /* ---- Fixed-based operators ---- */
|
|
30
34
|
|
|
31
|
-
export declare function
|
|
32
|
-
|
|
35
|
+
// export declare function cos<A extends Mappable[]>(...x: A):
|
|
36
|
+
// MapfunWrap<typeof Math.cos, A>;
|
|
33
37
|
|
|
34
|
-
export declare function
|
|
35
|
-
|
|
38
|
+
// export declare function sin<A extends Mappable[]>(...x: A):
|
|
39
|
+
// MapfunWrap<Math.sin, A>;
|
|
36
40
|
|
|
37
|
-
export declare function
|
|
38
|
-
|
|
41
|
+
// export declare function tan<A extends Mappable[]>(...x: A):
|
|
42
|
+
// MapfunWrap<Math.tan, A>;
|
|
39
43
|
|
|
40
|
-
export declare function
|
|
41
|
-
|
|
44
|
+
// export declare function sec<A extends Mappable[]>(...x: A):
|
|
45
|
+
// MapfunWrap<Math.sec, A>;
|
|
42
46
|
|
|
43
|
-
export declare function
|
|
44
|
-
|
|
47
|
+
// export declare function sinc<A extends Mappable[]>(...x: A):
|
|
48
|
+
// MapfunWrap<Math.sinc, A>;
|
|
45
49
|
|
|
46
|
-
export declare function
|
|
47
|
-
|
|
50
|
+
// export declare function csc<A extends Mappable[]>(...x: A):
|
|
51
|
+
// MapfunWrap<Math.csc, A>;
|
|
48
52
|
|
|
49
|
-
export declare function
|
|
50
|
-
|
|
53
|
+
// export declare function cot<A extends Mappable[]>(...x: A):
|
|
54
|
+
// MapfunWrap<Math.cot, A>;
|
|
51
55
|
|
|
52
|
-
export declare function
|
|
53
|
-
|
|
56
|
+
// export declare function acos<A extends Mappable[]>(...x: A):
|
|
57
|
+
// MapfunWrap<Math.acos, A>;
|
|
54
58
|
|
|
55
|
-
export declare function
|
|
56
|
-
|
|
59
|
+
// export declare function asin<A extends Mappable[]>(...x: A):
|
|
60
|
+
// MapfunWrap<Math.asin, A>;
|
|
57
61
|
|
|
58
|
-
export declare function
|
|
59
|
-
|
|
62
|
+
// export declare function atan<A extends Mappable[]>(...x: A):
|
|
63
|
+
// MapfunWrap<Math.atan, A>;
|
|
60
64
|
|
|
61
|
-
export declare function
|
|
62
|
-
|
|
65
|
+
// export declare function acot<A extends Mappable[]>(...x: A):
|
|
66
|
+
// MapfunWrap<Math.acot, A>;
|
|
63
67
|
|
|
64
|
-
export declare function
|
|
65
|
-
|
|
68
|
+
// export declare function cosh<A extends Mappable[]>(...x: A):
|
|
69
|
+
// MapfunWrap<Math.cosh, A>;
|
|
66
70
|
|
|
67
|
-
export declare function
|
|
68
|
-
|
|
71
|
+
// export declare function sinh<A extends Mappable[]>(...x: A):
|
|
72
|
+
// MapfunWrap<Math.sinh, A>;
|
|
69
73
|
|
|
70
|
-
export declare function
|
|
71
|
-
|
|
74
|
+
// export declare function tanh<A extends Mappable[]>(...x: A):
|
|
75
|
+
// MapfunWrap<Math.tanh, A>;
|
|
72
76
|
|
|
73
|
-
export declare function
|
|
74
|
-
|
|
77
|
+
// export declare function coth<A extends Mappable[]>(...x: A):
|
|
78
|
+
// MapfunWrap<Math.coth, A>;
|
|
75
79
|
|
|
76
|
-
export declare function
|
|
77
|
-
|
|
80
|
+
// export declare function acosh<A extends Mappable[]>(...x: A):
|
|
81
|
+
// MapfunWrap<Math.acosh, A>;
|
|
78
82
|
|
|
79
|
-
export declare function
|
|
80
|
-
|
|
83
|
+
// export declare function asinh<A extends Mappable[]>(...x: A):
|
|
84
|
+
// MapfunWrap<Math.asinh, A>;
|
|
81
85
|
|
|
82
|
-
|
|
86
|
+
// export declare function atanh<A extends Mappable[]>(...x: A):
|
|
87
|
+
// MapfunWrap<Math.atanh, A>;
|
|
83
88
|
|
|
84
|
-
|
|
85
|
-
MapfunWrap<typeof Math.ceil, A>;
|
|
89
|
+
// /* ---- Math wrappers ---- */
|
|
86
90
|
|
|
87
|
-
export declare function
|
|
88
|
-
|
|
91
|
+
// export declare function ceil<A extends Mappable[]>(...x: A):
|
|
92
|
+
// MapfunWrap<typeof Math.ceil, A>;
|
|
89
93
|
|
|
90
|
-
export declare function
|
|
91
|
-
|
|
94
|
+
// export declare function floor<A extends Mappable[]>(...x: A):
|
|
95
|
+
// MapfunWrap<typeof Math.floor, A>;
|
|
92
96
|
|
|
93
|
-
export declare function
|
|
94
|
-
|
|
97
|
+
// export declare function round<A extends Mappable[]>(...x: A):
|
|
98
|
+
// MapfunWrap<typeof Math.round, A>;
|
|
95
99
|
|
|
96
|
-
export declare function
|
|
97
|
-
|
|
100
|
+
// export declare function sign<A extends Mappable[]>(...x: A):
|
|
101
|
+
// MapfunWrap<typeof Math.sign, A>;
|
|
98
102
|
|
|
99
|
-
export declare function
|
|
100
|
-
|
|
103
|
+
// export declare function sig<A extends Mappable[]>(...x: A):
|
|
104
|
+
// MapfunWrap<(n: number) => number, A>;
|
|
101
105
|
|
|
106
|
+
// export declare function fact<A extends Mappable[]>(...x: A):
|
|
107
|
+
// MapfunWrap<(n: number) => number, A>;
|
|
102
108
|
|
|
103
|
-
/* -------------------- pow -------------------- */
|
|
104
109
|
|
|
105
|
-
|
|
106
|
-
export declare function pow(x: number, n: Complex): Complex;
|
|
107
|
-
export declare function pow(x: number, n: Mappable): any;
|
|
110
|
+
// /* -------------------- pow -------------------- */
|
|
108
111
|
|
|
109
|
-
export declare function pow(x:
|
|
110
|
-
export declare function pow(x:
|
|
111
|
-
export declare function pow(x:
|
|
112
|
+
// export declare function pow(x: number, n: number): number;
|
|
113
|
+
// export declare function pow(x: number, n: Complex): Complex;
|
|
114
|
+
// export declare function pow(x: number, n: Mappable): any;
|
|
112
115
|
|
|
113
|
-
export declare function pow(x:
|
|
114
|
-
export declare function pow(x:
|
|
116
|
+
// export declare function pow(x: Complex, n: number): Complex;
|
|
117
|
+
// export declare function pow(x: Complex, n: Complex): Complex;
|
|
118
|
+
// export declare function pow(x: Complex, n: Mappable): any;
|
|
115
119
|
|
|
120
|
+
// export declare function pow(x: Mappable[], n: number): any[];
|
|
121
|
+
// export declare function pow(x: Mappable[], n: Mappable[]): any[];
|
|
116
122
|
|
|
117
|
-
/* -------------------- sqrtn -------------------- */
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
export declare function sqrtn(x: number, n: Mappable): any;
|
|
124
|
+
// /* -------------------- sqrtn -------------------- */
|
|
121
125
|
|
|
122
|
-
export declare function sqrtn(x:
|
|
123
|
-
export declare function sqrtn(x:
|
|
126
|
+
// export declare function sqrtn(x: number, n: number): number;
|
|
127
|
+
// export declare function sqrtn(x: number, n: Mappable): any;
|
|
124
128
|
|
|
125
|
-
export declare function sqrtn(x:
|
|
126
|
-
export declare function sqrtn(x:
|
|
129
|
+
// export declare function sqrtn(x: Complex, n: number): Complex;
|
|
130
|
+
// export declare function sqrtn(x: Complex, n: Mappable): any;
|
|
127
131
|
|
|
132
|
+
// export declare function sqrtn(x: Mappable[], n: number): any[];
|
|
133
|
+
// export declare function sqrtn(x: Mappable[], n: Mappable[]): any[];
|
|
128
134
|
|
|
129
|
-
/* -------------------- atan2 -------------------- */
|
|
130
135
|
|
|
131
|
-
|
|
132
|
-
export declare function atan2(x: number, y: Mappable, rad?: boolean): any;
|
|
133
|
-
export declare function atan2(x: Mappable, y: number, rad?: boolean): any;
|
|
134
|
-
export declare function atan2(x: Mappable[], y: Mappable[], rad?: boolean): any[];
|
|
136
|
+
// /* -------------------- atan2 -------------------- */
|
|
135
137
|
|
|
138
|
+
// export declare function atan2(x: number, y: number, rad?: boolean): number;
|
|
139
|
+
// export declare function atan2(x: number, y: Mappable, rad?: boolean): any;
|
|
140
|
+
// export declare function atan2(x: Mappable, y: number, rad?: boolean): any;
|
|
141
|
+
// export declare function atan2(x: Mappable[], y: Mappable[], rad?: boolean): any[];
|
|
136
142
|
|
|
137
|
-
/* -------------------- hypot -------------------- */
|
|
138
143
|
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
// /* -------------------- hypot -------------------- */
|
|
145
|
+
|
|
146
|
+
// export declare function hypot(...x: number[]): number;
|
|
147
|
+
// export declare function hypot(...x: Mappable[]): any;
|
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
import type { Complex } from "../../complex/index.d.ts";
|
|
2
|
-
// import type { Matrix } from "../../matrix/index.d.ts";
|
|
3
2
|
import { Matrix } from '../../../../src/math/matrix/index.js'
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
11
|
-
|
|
4
|
+
export type LogicValue = 0 | 1 | Complex | Matrix;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Logical NOT operation.
|
|
8
|
+
*/
|
|
9
|
+
export declare const not: (
|
|
10
|
+
x: LogicValue
|
|
11
|
+
) => LogicValue;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Logical AND operation.
|
|
15
|
+
*/
|
|
16
|
+
export declare const and: (
|
|
17
|
+
...x: LogicValue[]
|
|
18
|
+
) => LogicValue;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Logical OR operation.
|
|
22
|
+
*/
|
|
23
|
+
export declare const or: (
|
|
24
|
+
...x: LogicValue[]
|
|
25
|
+
) => LogicValue;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Logical XOR operation.
|
|
29
|
+
*/
|
|
30
|
+
export declare const xor: (
|
|
31
|
+
...x: LogicValue[]
|
|
32
|
+
) => LogicValue;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Logical NAND operation.
|
|
36
|
+
*/
|
|
37
|
+
export declare const nand: (
|
|
38
|
+
...x: LogicValue[]
|
|
39
|
+
) => LogicValue;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Logical NOR operation.
|
|
43
|
+
*/
|
|
44
|
+
export declare const nor: (
|
|
45
|
+
...x: LogicValue[]
|
|
46
|
+
) => LogicValue;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Logical XNOR operation.
|
|
50
|
+
*/
|
|
51
|
+
export declare const xnor: (
|
|
52
|
+
...x: LogicValue[]
|
|
53
|
+
) => LogicValue;
|
|
@@ -1,87 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type TypedArray =
|
|
2
|
+
| Int8Array
|
|
3
|
+
| Uint8Array
|
|
4
|
+
| Uint8ClampedArray
|
|
5
|
+
| Int16Array
|
|
6
|
+
| Uint16Array
|
|
7
|
+
| Int32Array
|
|
8
|
+
| Uint32Array
|
|
9
|
+
| Float32Array
|
|
10
|
+
| Float64Array
|
|
11
|
+
| BigInt64Array
|
|
12
|
+
| BigUint64Array;
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
15
|
+
* Custom mapped type that recursively applies leaf transformation `R`
|
|
16
|
+
* while strictly maintaining structure (tuples, arrays, sets, maps, objects).
|
|
7
17
|
*/
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
| bigint
|
|
17
|
-
| undefined
|
|
18
|
-
| null
|
|
19
|
-
| { readonly __mapfun__: boolean };
|
|
20
|
-
|
|
21
|
-
export type Mappable =
|
|
22
|
-
| number
|
|
23
|
-
| string
|
|
24
|
-
| boolean
|
|
25
|
-
| bigint
|
|
26
|
-
| undefined
|
|
27
|
-
| null
|
|
28
|
-
| Matrix
|
|
29
|
-
| MapfunPrimitiveLike
|
|
30
|
-
| any[]
|
|
31
|
-
| Set<any>
|
|
32
|
-
| Map<any, any>
|
|
33
|
-
| object;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* mapfun transform rules
|
|
37
|
-
*/
|
|
38
|
-
export type MapfunResult<F extends (x: any) => any, T> =
|
|
39
|
-
// Objects with __mapfun__ → treat as primitive (call fun(x))
|
|
40
|
-
// T extends MapfunPrimitiveLike
|
|
41
|
-
// ? ReturnType<F> :
|
|
42
|
-
|
|
43
|
-
// Matrix → always return Matrix (your JS logic rebuilds a new Matrix)
|
|
44
|
-
|
|
45
|
-
T extends PrimitiveLike
|
|
46
|
-
? ReturnType<F> :
|
|
47
|
-
// T extends Complex
|
|
48
|
-
// ? T :
|
|
49
|
-
T extends Matrix
|
|
50
|
-
? T :
|
|
51
|
-
|
|
52
|
-
// Array → deep-map
|
|
18
|
+
export type MapFunResult<T, R> =
|
|
19
|
+
// 1. Primitive types or explicit mapfun override tag
|
|
20
|
+
T extends number | string | boolean | bigint | symbol | null | undefined | { __mapfun__?: any }
|
|
21
|
+
? R
|
|
22
|
+
: // 2. Preserve Tuple length and element order precisely
|
|
23
|
+
T extends [infer Head, ...infer Tail]
|
|
24
|
+
? [MapFunResult<Head, R>, ...MapFunResult<Tail, R>]
|
|
25
|
+
: // 3. Standard homogeneous Arrays
|
|
53
26
|
T extends Array<infer U>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
27
|
+
? Array<MapFunResult<U, R>>
|
|
28
|
+
: // 4. TypedArray views
|
|
29
|
+
T extends TypedArray
|
|
30
|
+
? T
|
|
31
|
+
: // 5. Sets
|
|
57
32
|
T extends Set<infer U>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// Map → deep-map values
|
|
33
|
+
? Set<MapFunResult<U, R>>
|
|
34
|
+
: // 6. Maps
|
|
61
35
|
T extends Map<infer K, infer V>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
? Map<K, MapFunResult<V, R>>
|
|
37
|
+
: // 7. Matrix objects
|
|
38
|
+
T extends { isMatrix: () => boolean }
|
|
39
|
+
? T
|
|
40
|
+
: // 8. Plain Objects (preserve property keys)
|
|
65
41
|
T extends object
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* mapfun main declaration
|
|
80
|
-
*/
|
|
81
|
-
export declare function mapfun<
|
|
82
|
-
F extends (x: any) => any,
|
|
83
|
-
A extends Mappable[]
|
|
84
|
-
>(
|
|
85
|
-
fun: F,
|
|
86
|
-
...values: A
|
|
87
|
-
): UnwrapSingle<{ [K in keyof A]: MapfunResult<F, A[K]> }>;
|
|
42
|
+
? { [K in keyof T]: MapFunResult<T[K], R> }
|
|
43
|
+
: R;
|
|
44
|
+
|
|
45
|
+
export function mapfun<T, R>(
|
|
46
|
+
fun: (value: any) => R,
|
|
47
|
+
x: T
|
|
48
|
+
): MapFunResult<T, R>;
|
|
49
|
+
|
|
50
|
+
export function mapfun<T extends any[], R>(
|
|
51
|
+
fun: (value: any) => R,
|
|
52
|
+
...X: T
|
|
53
|
+
): { [K in keyof T]: MapFunResult<T[K], R> };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// import { Complex } from "../../../src/math/Complex/index.js";
|
|
2
|
+
// import { Matrix } from "../../../src/math/matrix/index.js";
|
|
3
|
+
|
|
4
|
+
// /**
|
|
5
|
+
// * Objects that behave like primitives for mapfun,
|
|
6
|
+
// * meaning fun(x) is applied directly without recursion.
|
|
7
|
+
// */
|
|
8
|
+
// export interface MapfunPrimitiveLike {
|
|
9
|
+
// __mapfun__?: boolean;
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
// export type PrimitiveLike =
|
|
13
|
+
// | number
|
|
14
|
+
// | boolean
|
|
15
|
+
// | string
|
|
16
|
+
// | bigint
|
|
17
|
+
// | undefined
|
|
18
|
+
// | null
|
|
19
|
+
// | { readonly __mapfun__: boolean };
|
|
20
|
+
|
|
21
|
+
// export type Mappable =
|
|
22
|
+
// | number
|
|
23
|
+
// | string
|
|
24
|
+
// | boolean
|
|
25
|
+
// | bigint
|
|
26
|
+
// | undefined
|
|
27
|
+
// | null
|
|
28
|
+
// | Matrix
|
|
29
|
+
// | MapfunPrimitiveLike
|
|
30
|
+
// | any[]
|
|
31
|
+
// | Set<any>
|
|
32
|
+
// | Map<any, any>
|
|
33
|
+
// | object;
|
|
34
|
+
|
|
35
|
+
// /**
|
|
36
|
+
// * mapfun transform rules
|
|
37
|
+
// */
|
|
38
|
+
// export type MapfunResult<F extends (x: any) => any, T> =
|
|
39
|
+
// // Objects with __mapfun__ → treat as primitive (call fun(x))
|
|
40
|
+
// // T extends MapfunPrimitiveLike
|
|
41
|
+
// // ? ReturnType<F> :
|
|
42
|
+
|
|
43
|
+
// // Matrix → always return Matrix (your JS logic rebuilds a new Matrix)
|
|
44
|
+
|
|
45
|
+
// T extends PrimitiveLike
|
|
46
|
+
// ? ReturnType<F> :
|
|
47
|
+
// // T extends Complex
|
|
48
|
+
// // ? T :
|
|
49
|
+
// T extends Matrix
|
|
50
|
+
// ? T :
|
|
51
|
+
|
|
52
|
+
// // Array → deep-map
|
|
53
|
+
// T extends Array<infer U>
|
|
54
|
+
// ? Array<MapfunResult<F, U>> :
|
|
55
|
+
|
|
56
|
+
// // Set → deep-map
|
|
57
|
+
// T extends Set<infer U>
|
|
58
|
+
// ? Set<MapfunResult<F, U>> :
|
|
59
|
+
|
|
60
|
+
// // Map → deep-map values
|
|
61
|
+
// T extends Map<infer K, infer V>
|
|
62
|
+
// ? Map<K, MapfunResult<F, V>> :
|
|
63
|
+
|
|
64
|
+
// // Other objects → recursively map fields
|
|
65
|
+
// T extends object
|
|
66
|
+
// ? { [K in keyof T]: MapfunResult<F, T[K]> } :
|
|
67
|
+
|
|
68
|
+
// // Primitive
|
|
69
|
+
// ReturnType<F>;
|
|
70
|
+
|
|
71
|
+
// /**
|
|
72
|
+
// * If only one argument → return mapped value
|
|
73
|
+
// * If multiple → return tuple of mapped values
|
|
74
|
+
// */
|
|
75
|
+
// type UnwrapSingle<T extends unknown[]> =
|
|
76
|
+
// T extends [infer U] ? U : { [K in keyof T]: T[K] };
|
|
77
|
+
|
|
78
|
+
// /**
|
|
79
|
+
// * mapfun main declaration
|
|
80
|
+
// */
|
|
81
|
+
// export declare function mapfun<
|
|
82
|
+
// F extends (x: any) => any,
|
|
83
|
+
// A extends Mappable[]
|
|
84
|
+
// >(
|
|
85
|
+
// fun: F,
|
|
86
|
+
// ...values: A
|
|
87
|
+
// ): UnwrapSingle<{ [K in keyof A]: MapfunResult<F, A[K]> }>;
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
export type Primitive =
|
|
91
|
+
string |
|
|
92
|
+
number |
|
|
93
|
+
boolean |
|
|
94
|
+
bigint |
|
|
95
|
+
symbol |
|
|
96
|
+
null |
|
|
97
|
+
undefined;
|
|
98
|
+
|
|
99
|
+
export interface MapfunCompatible<T = any> {
|
|
100
|
+
__mapfun__?: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ComplexLike {
|
|
104
|
+
isComplex(): boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface MatrixLike {
|
|
108
|
+
rows: number;
|
|
109
|
+
cols: number;
|
|
110
|
+
|
|
111
|
+
isMatrix(): boolean;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type Mappable<T = any> =
|
|
115
|
+
| T
|
|
116
|
+
| Primitive
|
|
117
|
+
| Mappable<T>[]
|
|
118
|
+
| ArrayLike<T>
|
|
119
|
+
| Set<Mappable<T>>
|
|
120
|
+
| Map<any, Mappable<T>>
|
|
121
|
+
| MapfunCompatible<T>
|
|
122
|
+
| ComplexLike
|
|
123
|
+
| MatrixLike
|
|
124
|
+
| Record<string, Mappable<T>>;
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Applies a function recursively to values inside
|
|
129
|
+
* arrays, typed arrays, sets, maps, objects,
|
|
130
|
+
* complex values and matrices.
|
|
131
|
+
*
|
|
132
|
+
* @param fun Transformation function.
|
|
133
|
+
* @param X Values to transform.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* mapfun(x => x * 2, [1,2,3])
|
|
137
|
+
* // [2,4,6]
|
|
138
|
+
*/
|
|
139
|
+
export declare function mapfun<T, R>(
|
|
140
|
+
fun: (value: T) => R,
|
|
141
|
+
x: Mappable<T>
|
|
142
|
+
): R;
|
|
143
|
+
|
|
144
|
+
export declare function mapfun<T, R>(
|
|
145
|
+
fun: (value: T) => R,
|
|
146
|
+
x: Mappable<T>,
|
|
147
|
+
...X: Mappable<T>[]
|
|
148
|
+
): R[];
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Applies a function to supported mathematical structures.
|
|
153
|
+
*
|
|
154
|
+
* Handles Complex and Matrix instances specially.
|
|
155
|
+
*
|
|
156
|
+
* @param x Input value.
|
|
157
|
+
* @param fn Transformation function.
|
|
158
|
+
*/
|
|
159
|
+
export declare function apply_fun<T, R>(
|
|
160
|
+
x: Mappable<T>,
|
|
161
|
+
fn: (value: T) => R
|
|
162
|
+
): Mappable<R>;
|