functionalscript 0.1.605 → 0.1.606
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/jsr.json +1 -1
- package/package.json +1 -1
- package/types/function/module.f.d.mts +33 -3
- package/types/function/module.f.mjs +28 -3
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -5,14 +5,26 @@ declare namespace _default {
|
|
|
5
5
|
export { fn };
|
|
6
6
|
}
|
|
7
7
|
export default _default;
|
|
8
|
+
/**
|
|
9
|
+
* A generic function type.
|
|
10
|
+
*/
|
|
8
11
|
export type Func<I, O> = (_: I) => O;
|
|
12
|
+
/**
|
|
13
|
+
* A functional utility type that enables seamless chaining of transformations.
|
|
14
|
+
*/
|
|
9
15
|
export type Fn<I, O> = {
|
|
10
16
|
readonly result: Func<I, O>;
|
|
11
17
|
readonly then: <T>(g: Func<O, T>) => Fn<I, T>;
|
|
12
18
|
};
|
|
13
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* A generic identity function.
|
|
21
|
+
*
|
|
22
|
+
* @type {<T>(value: T) => T}
|
|
23
|
+
*/
|
|
14
24
|
declare const identity: <T>(value: T) => T;
|
|
15
25
|
/**
|
|
26
|
+
* A generic function type.
|
|
27
|
+
*
|
|
16
28
|
* @template I
|
|
17
29
|
* @template O
|
|
18
30
|
* @typedef {(_: I) => O} Func
|
|
@@ -23,14 +35,32 @@ declare const identity: <T>(value: T) => T;
|
|
|
23
35
|
* @type {<I, X>(g: Func<I, X>) => <O>(f: Func<X, O>) => Func<I, O>}
|
|
24
36
|
*/
|
|
25
37
|
declare const compose: <I, X>(g: Func<I, X>) => <O>(f: Func<X, O>) => Func<I, O>;
|
|
26
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Flips the arguments of a curried function.
|
|
40
|
+
*
|
|
41
|
+
* @type {<A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a: A) => C}
|
|
42
|
+
*/
|
|
27
43
|
declare const flip: <A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a: A) => C;
|
|
28
44
|
/**
|
|
45
|
+
* A functional utility type that enables seamless chaining of transformations.
|
|
46
|
+
*
|
|
29
47
|
* @template I,O
|
|
30
48
|
* @typedef {{
|
|
31
49
|
* readonly result: Func<I, O>
|
|
32
50
|
* readonly then: <T>(g: Func<O, T>) => Fn<I, T>
|
|
33
51
|
* }} Fn
|
|
34
52
|
*/
|
|
35
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Creates an `Fn` instance from a function, enabling chaining of transformations.
|
|
55
|
+
*
|
|
56
|
+
* @type {<I, O>(f: (i: I) => O) => Fn<I, O>}
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const add2 = (x) => x + 2; // Adds 2
|
|
60
|
+
* const multiply3 = (x) => x * 3; // Multiplies by 3
|
|
61
|
+
*
|
|
62
|
+
* // Chain transformations
|
|
63
|
+
* const add2multiply3 = fn(add2).then(multiply3).result;
|
|
64
|
+
* const result = add2multiply3(5); // result is 21. (5 + 2) * 3.
|
|
65
|
+
*/
|
|
36
66
|
declare const fn: <I, O>(f: (i: I) => O) => Fn<I, O>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
+
|
|
2
3
|
/**
|
|
4
|
+
* A generic function type.
|
|
5
|
+
*
|
|
3
6
|
* @template I
|
|
4
7
|
* @template O
|
|
5
8
|
* @typedef {(_: I) => O} Func
|
|
@@ -12,13 +15,23 @@
|
|
|
12
15
|
*/
|
|
13
16
|
const compose = g => f => x => f(g(x))
|
|
14
17
|
|
|
15
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* A generic identity function.
|
|
20
|
+
*
|
|
21
|
+
* @type {<T>(value: T) => T}
|
|
22
|
+
*/
|
|
16
23
|
const identity = value => value
|
|
17
24
|
|
|
18
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Flips the arguments of a curried function.
|
|
27
|
+
*
|
|
28
|
+
* @type {<A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a: A) => C}
|
|
29
|
+
*/
|
|
19
30
|
const flip = f => b => a => f(a)(b)
|
|
20
31
|
|
|
21
32
|
/**
|
|
33
|
+
* A functional utility type that enables seamless chaining of transformations.
|
|
34
|
+
*
|
|
22
35
|
* @template I,O
|
|
23
36
|
* @typedef {{
|
|
24
37
|
* readonly result: Func<I, O>
|
|
@@ -26,7 +39,19 @@ const flip = f => b => a => f(a)(b)
|
|
|
26
39
|
* }} Fn
|
|
27
40
|
*/
|
|
28
41
|
|
|
29
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Creates an `Fn` instance from a function, enabling chaining of transformations.
|
|
44
|
+
*
|
|
45
|
+
* @type {<I, O>(f: (i: I) => O) => Fn<I, O>}
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const add2 = (x) => x + 2; // Adds 2
|
|
49
|
+
* const multiply3 = (x) => x * 3; // Multiplies by 3
|
|
50
|
+
*
|
|
51
|
+
* // Chain transformations
|
|
52
|
+
* const add2multiply3 = fn(add2).then(multiply3).result;
|
|
53
|
+
* const result = add2multiply3(5); // result is 21. (5 + 2) * 3.
|
|
54
|
+
*/
|
|
30
55
|
const fn = result => ({
|
|
31
56
|
result,
|
|
32
57
|
then: g => fn(compose(result)(g))
|