@nlozgachev/pipelined 0.12.0 → 0.14.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/LICENCE +28 -0
- package/README.md +1 -1
- package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
- package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
- package/dist/Task-Bd3gXPRQ.d.mts +677 -0
- package/dist/Task-BjAkkD6t.d.ts +677 -0
- package/dist/chunk-4TXC322E.mjs +136 -0
- package/dist/chunk-BYWKZLHM.mjs +10 -0
- package/dist/chunk-DBIC62UV.mjs +6 -0
- package/dist/chunk-FAZN3IWZ.mjs +554 -0
- package/dist/chunk-QPTGO5AS.mjs +150 -0
- package/dist/chunk-UV2HMF2A.mjs +514 -0
- package/dist/composition.d.mts +495 -0
- package/dist/composition.d.ts +495 -0
- package/dist/composition.js +188 -0
- package/dist/composition.mjs +58 -0
- package/dist/core.d.mts +2170 -0
- package/dist/core.d.ts +2170 -0
- package/dist/core.js +698 -0
- package/dist/core.mjs +42 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1421 -0
- package/dist/index.mjs +120 -0
- package/dist/types.d.mts +54 -0
- package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
- package/dist/types.js +41 -0
- package/dist/types.mjs +10 -0
- package/dist/utils.d.mts +1285 -0
- package/dist/utils.d.ts +1285 -0
- package/dist/utils.js +722 -0
- package/dist/utils.mjs +18 -0
- package/package.json +64 -69
- package/esm/mod.js +0 -3
- package/esm/package.json +0 -3
- package/esm/src/Composition/compose.js +0 -3
- package/esm/src/Composition/converge.js +0 -3
- package/esm/src/Composition/curry.js +0 -42
- package/esm/src/Composition/flip.js +0 -20
- package/esm/src/Composition/flow.js +0 -8
- package/esm/src/Composition/fn.js +0 -85
- package/esm/src/Composition/index.js +0 -13
- package/esm/src/Composition/juxt.js +0 -3
- package/esm/src/Composition/memoize.js +0 -66
- package/esm/src/Composition/not.js +0 -25
- package/esm/src/Composition/on.js +0 -12
- package/esm/src/Composition/pipe.js +0 -3
- package/esm/src/Composition/tap.js +0 -33
- package/esm/src/Composition/uncurry.js +0 -32
- package/esm/src/Core/Deferred.js +0 -30
- package/esm/src/Core/InternalTypes.js +0 -1
- package/esm/src/Core/Lens.js +0 -98
- package/esm/src/Core/Logged.js +0 -111
- package/esm/src/Core/Option.js +0 -191
- package/esm/src/Core/Optional.js +0 -160
- package/esm/src/Core/Predicate.js +0 -133
- package/esm/src/Core/Reader.js +0 -134
- package/esm/src/Core/Refinement.js +0 -115
- package/esm/src/Core/RemoteData.js +0 -211
- package/esm/src/Core/Result.js +0 -170
- package/esm/src/Core/State.js +0 -181
- package/esm/src/Core/Task.js +0 -223
- package/esm/src/Core/TaskOption.js +0 -106
- package/esm/src/Core/TaskResult.js +0 -127
- package/esm/src/Core/TaskValidation.js +0 -128
- package/esm/src/Core/These.js +0 -245
- package/esm/src/Core/Tuple.js +0 -112
- package/esm/src/Core/Validation.js +0 -212
- package/esm/src/Core/index.js +0 -18
- package/esm/src/Types/Brand.js +0 -28
- package/esm/src/Types/NonEmptyList.js +0 -14
- package/esm/src/Types/index.js +0 -2
- package/esm/src/Utils/Arr.js +0 -570
- package/esm/src/Utils/Dict.js +0 -421
- package/esm/src/Utils/Num.js +0 -124
- package/esm/src/Utils/Rec.js +0 -241
- package/esm/src/Utils/Str.js +0 -134
- package/esm/src/Utils/Uniq.js +0 -265
- package/esm/src/Utils/index.js +0 -6
- package/script/mod.js +0 -19
- package/script/package.json +0 -3
- package/script/src/Composition/compose.js +0 -6
- package/script/src/Composition/converge.js +0 -6
- package/script/src/Composition/curry.js +0 -48
- package/script/src/Composition/flip.js +0 -24
- package/script/src/Composition/flow.js +0 -11
- package/script/src/Composition/fn.js +0 -98
- package/script/src/Composition/index.js +0 -29
- package/script/src/Composition/juxt.js +0 -6
- package/script/src/Composition/memoize.js +0 -71
- package/script/src/Composition/not.js +0 -29
- package/script/src/Composition/on.js +0 -16
- package/script/src/Composition/pipe.js +0 -6
- package/script/src/Composition/tap.js +0 -37
- package/script/src/Composition/uncurry.js +0 -38
- package/script/src/Core/Deferred.js +0 -33
- package/script/src/Core/InternalTypes.js +0 -2
- package/script/src/Core/Lens.js +0 -101
- package/script/src/Core/Logged.js +0 -114
- package/script/src/Core/Option.js +0 -194
- package/script/src/Core/Optional.js +0 -163
- package/script/src/Core/Predicate.js +0 -136
- package/script/src/Core/Reader.js +0 -137
- package/script/src/Core/Refinement.js +0 -118
- package/script/src/Core/RemoteData.js +0 -214
- package/script/src/Core/Result.js +0 -173
- package/script/src/Core/State.js +0 -184
- package/script/src/Core/Task.js +0 -226
- package/script/src/Core/TaskOption.js +0 -109
- package/script/src/Core/TaskResult.js +0 -130
- package/script/src/Core/TaskValidation.js +0 -131
- package/script/src/Core/These.js +0 -248
- package/script/src/Core/Tuple.js +0 -115
- package/script/src/Core/Validation.js +0 -215
- package/script/src/Core/index.js +0 -34
- package/script/src/Types/Brand.js +0 -31
- package/script/src/Types/NonEmptyList.js +0 -18
- package/script/src/Types/index.js +0 -18
- package/script/src/Utils/Arr.js +0 -573
- package/script/src/Utils/Dict.js +0 -424
- package/script/src/Utils/Num.js +0 -127
- package/script/src/Utils/Rec.js +0 -244
- package/script/src/Utils/Str.js +0 -137
- package/script/src/Utils/Uniq.js +0 -268
- package/script/src/Utils/index.js +0 -22
- package/types/mod.d.ts +0 -4
- package/types/mod.d.ts.map +0 -1
- package/types/src/Composition/compose.d.ts +0 -33
- package/types/src/Composition/compose.d.ts.map +0 -1
- package/types/src/Composition/converge.d.ts +0 -21
- package/types/src/Composition/converge.d.ts.map +0 -1
- package/types/src/Composition/curry.d.ts +0 -43
- package/types/src/Composition/curry.d.ts.map +0 -1
- package/types/src/Composition/flip.d.ts +0 -21
- package/types/src/Composition/flip.d.ts.map +0 -1
- package/types/src/Composition/flow.d.ts +0 -56
- package/types/src/Composition/flow.d.ts.map +0 -1
- package/types/src/Composition/fn.d.ts +0 -76
- package/types/src/Composition/fn.d.ts.map +0 -1
- package/types/src/Composition/index.d.ts +0 -14
- package/types/src/Composition/index.d.ts.map +0 -1
- package/types/src/Composition/juxt.d.ts +0 -18
- package/types/src/Composition/juxt.d.ts.map +0 -1
- package/types/src/Composition/memoize.d.ts +0 -46
- package/types/src/Composition/memoize.d.ts.map +0 -1
- package/types/src/Composition/not.d.ts +0 -26
- package/types/src/Composition/not.d.ts.map +0 -1
- package/types/src/Composition/on.d.ts +0 -13
- package/types/src/Composition/on.d.ts.map +0 -1
- package/types/src/Composition/pipe.d.ts +0 -56
- package/types/src/Composition/pipe.d.ts.map +0 -1
- package/types/src/Composition/tap.d.ts +0 -31
- package/types/src/Composition/tap.d.ts.map +0 -1
- package/types/src/Composition/uncurry.d.ts +0 -54
- package/types/src/Composition/uncurry.d.ts.map +0 -1
- package/types/src/Core/Deferred.d.ts +0 -49
- package/types/src/Core/Deferred.d.ts.map +0 -1
- package/types/src/Core/InternalTypes.d.ts +0 -23
- package/types/src/Core/InternalTypes.d.ts.map +0 -1
- package/types/src/Core/Lens.d.ts +0 -118
- package/types/src/Core/Lens.d.ts.map +0 -1
- package/types/src/Core/Logged.d.ts +0 -126
- package/types/src/Core/Logged.d.ts.map +0 -1
- package/types/src/Core/Option.d.ts +0 -209
- package/types/src/Core/Option.d.ts.map +0 -1
- package/types/src/Core/Optional.d.ts +0 -158
- package/types/src/Core/Optional.d.ts.map +0 -1
- package/types/src/Core/Predicate.d.ts +0 -161
- package/types/src/Core/Predicate.d.ts.map +0 -1
- package/types/src/Core/Reader.d.ts +0 -156
- package/types/src/Core/Reader.d.ts.map +0 -1
- package/types/src/Core/Refinement.d.ts +0 -138
- package/types/src/Core/Refinement.d.ts.map +0 -1
- package/types/src/Core/RemoteData.d.ts +0 -197
- package/types/src/Core/RemoteData.d.ts.map +0 -1
- package/types/src/Core/Result.d.ts +0 -182
- package/types/src/Core/Result.d.ts.map +0 -1
- package/types/src/Core/State.d.ts +0 -192
- package/types/src/Core/State.d.ts.map +0 -1
- package/types/src/Core/Task.d.ts +0 -219
- package/types/src/Core/Task.d.ts.map +0 -1
- package/types/src/Core/TaskOption.d.ts +0 -121
- package/types/src/Core/TaskOption.d.ts.map +0 -1
- package/types/src/Core/TaskResult.d.ts +0 -119
- package/types/src/Core/TaskResult.d.ts.map +0 -1
- package/types/src/Core/TaskValidation.d.ts +0 -144
- package/types/src/Core/TaskValidation.d.ts.map +0 -1
- package/types/src/Core/These.d.ts +0 -225
- package/types/src/Core/These.d.ts.map +0 -1
- package/types/src/Core/Tuple.d.ts +0 -129
- package/types/src/Core/Tuple.d.ts.map +0 -1
- package/types/src/Core/Validation.d.ts +0 -203
- package/types/src/Core/Validation.d.ts.map +0 -1
- package/types/src/Core/index.d.ts +0 -19
- package/types/src/Core/index.d.ts.map +0 -1
- package/types/src/Types/Brand.d.ts.map +0 -1
- package/types/src/Types/NonEmptyList.d.ts.map +0 -1
- package/types/src/Types/index.d.ts +0 -3
- package/types/src/Types/index.d.ts.map +0 -1
- package/types/src/Utils/Arr.d.ts +0 -403
- package/types/src/Utils/Arr.d.ts.map +0 -1
- package/types/src/Utils/Dict.d.ts +0 -310
- package/types/src/Utils/Dict.d.ts.map +0 -1
- package/types/src/Utils/Num.d.ts +0 -110
- package/types/src/Utils/Num.d.ts.map +0 -1
- package/types/src/Utils/Rec.d.ts +0 -159
- package/types/src/Utils/Rec.d.ts.map +0 -1
- package/types/src/Utils/Str.d.ts +0 -128
- package/types/src/Utils/Str.d.ts.map +0 -1
- package/types/src/Utils/Uniq.d.ts +0 -179
- package/types/src/Utils/Uniq.d.ts.map +0 -1
- package/types/src/Utils/index.d.ts +0 -7
- package/types/src/Utils/index.d.ts.map +0 -1
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { Option } from "../Core/Option.js";
|
|
2
|
-
/**
|
|
3
|
-
* Functional utilities for key-value dictionaries (`ReadonlyMap<K, V>`). All functions are pure
|
|
4
|
-
* and data-last — they compose naturally with `pipe`.
|
|
5
|
-
*
|
|
6
|
-
* Unlike plain objects (`Rec`), dictionaries support any key type, preserve insertion order, and
|
|
7
|
-
* make membership checks explicit via `lookup` returning `Option`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { Dict } from "@nlozgachev/pipelined/utils";
|
|
12
|
-
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
13
|
-
*
|
|
14
|
-
* const scores = pipe(
|
|
15
|
-
* Dict.fromEntries([["alice", 10], ["bob", 8], ["carol", 10]] as const),
|
|
16
|
-
* Dict.filter(n => n >= 10),
|
|
17
|
-
* Dict.map(n => `${n} points`),
|
|
18
|
-
* );
|
|
19
|
-
* // ReadonlyMap { "alice" => "10 points", "carol" => "10 points" }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare namespace Dict {
|
|
23
|
-
/**
|
|
24
|
-
* Creates an empty dictionary.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* Dict.empty<string, number>(); // ReadonlyMap {}
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
const empty: <K, V>() => ReadonlyMap<K, V>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a dictionary with a single entry.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* Dict.singleton("name", "Alice"); // ReadonlyMap { "name" => "Alice" }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
const singleton: <K, V>(key: K, value: V) => ReadonlyMap<K, V>;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a dictionary from an array of key-value pairs.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* Dict.fromEntries([["a", 1], ["b", 2]]); // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
const fromEntries: <K, V>(entries: readonly (readonly [K, V])[]) => ReadonlyMap<K, V>;
|
|
50
|
-
/**
|
|
51
|
-
* Creates a dictionary from a plain object. Keys are always strings.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* Dict.fromRecord({ a: 1, b: 2 }); // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
const fromRecord: <V>(rec: Readonly<Record<string, V>>) => ReadonlyMap<string, V>;
|
|
59
|
-
/**
|
|
60
|
-
* Groups elements of an array into a dictionary keyed by the result of `keyFn`. Each key maps
|
|
61
|
-
* to the array of elements that produced it, in insertion order. Uses the native `Map.groupBy`
|
|
62
|
-
* when available, falling back to a manual loop in older environments.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* pipe(
|
|
67
|
-
* [{ name: "alice", role: "admin" }, { name: "bob", role: "viewer" }, { name: "carol", role: "admin" }],
|
|
68
|
-
* Dict.groupBy(user => user.role),
|
|
69
|
-
* );
|
|
70
|
-
* // ReadonlyMap { "admin" => [alice, carol], "viewer" => [bob] }
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
const groupBy: <K, A>(keyFn: (a: A) => K) => (items: readonly A[]) => ReadonlyMap<K, readonly A[]>;
|
|
74
|
-
/**
|
|
75
|
-
* Returns `true` if the dictionary contains the given key.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* pipe(Dict.fromEntries([["a", 1]]), Dict.has("a")); // true
|
|
80
|
-
* pipe(Dict.fromEntries([["a", 1]]), Dict.has("b")); // false
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
const has: <K>(key: K) => <V>(m: ReadonlyMap<K, V>) => boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Looks up a value by key, returning `Some(value)` if found and `None` if not.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```ts
|
|
89
|
-
* pipe(Dict.fromEntries([["a", 1]]), Dict.lookup("a")); // Some(1)
|
|
90
|
-
* pipe(Dict.fromEntries([["a", 1]]), Dict.lookup("b")); // None
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
const lookup: <K>(key: K) => <V>(m: ReadonlyMap<K, V>) => Option<V>;
|
|
94
|
-
/**
|
|
95
|
-
* Returns the number of entries in the dictionary.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* Dict.size(Dict.fromEntries([["a", 1], ["b", 2]])); // 2
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
const size: <K, V>(m: ReadonlyMap<K, V>) => number;
|
|
103
|
-
/**
|
|
104
|
-
* Returns `true` if the dictionary has no entries.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* Dict.isEmpty(Dict.empty()); // true
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
const isEmpty: <K, V>(m: ReadonlyMap<K, V>) => boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Returns all keys as a readonly array, in insertion order.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* Dict.keys(Dict.fromEntries([["a", 1], ["b", 2]])); // ["a", "b"]
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
const keys: <K, V>(m: ReadonlyMap<K, V>) => readonly K[];
|
|
121
|
-
/**
|
|
122
|
-
* Returns all values as a readonly array, in insertion order.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* Dict.values(Dict.fromEntries([["a", 1], ["b", 2]])); // [1, 2]
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
const values: <K, V>(m: ReadonlyMap<K, V>) => readonly V[];
|
|
130
|
-
/**
|
|
131
|
-
* Returns all key-value pairs as a readonly array of tuples, in insertion order.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```ts
|
|
135
|
-
* Dict.entries(Dict.fromEntries([["a", 1], ["b", 2]])); // [["a", 1], ["b", 2]]
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
const entries: <K, V>(m: ReadonlyMap<K, V>) => readonly (readonly [K, V])[];
|
|
139
|
-
/**
|
|
140
|
-
* Returns a new dictionary with the given key set to the given value.
|
|
141
|
-
* If the key already exists, its value is replaced.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* pipe(Dict.fromEntries([["a", 1]]), Dict.insert("b", 2));
|
|
146
|
-
* // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
const insert: <K, V>(key: K, value: V) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
150
|
-
/**
|
|
151
|
-
* Returns a new dictionary with the given key removed.
|
|
152
|
-
* If the key does not exist, the dictionary is returned unchanged.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.remove("a"));
|
|
157
|
-
* // ReadonlyMap { "b" => 2 }
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
const remove: <K, V>(key: K) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
161
|
-
/**
|
|
162
|
-
* Returns a new dictionary with the value at `key` set by `f`. If the key does not exist,
|
|
163
|
-
* `f` receives `None`. If the key exists, `f` receives `Some(currentValue)`.
|
|
164
|
-
*
|
|
165
|
-
* Useful for incrementing counters, initialising defaults, or conditional updates.
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```ts
|
|
169
|
-
* import { Option } from "@nlozgachev/pipelined/core";
|
|
170
|
-
*
|
|
171
|
-
* const increment = (opt: Option<number>) => Option.getOrElse(() => 0)(opt) + 1;
|
|
172
|
-
* pipe(Dict.fromEntries([["views", 5]]), Dict.upsert("views", increment)); // { views: 6 }
|
|
173
|
-
* pipe(Dict.fromEntries([["views", 5]]), Dict.upsert("likes", increment)); // { views: 5, likes: 1 }
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
const upsert: <K, V>(key: K, f: (existing: Option<V>) => V) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
177
|
-
/**
|
|
178
|
-
* Transforms each value in the dictionary.
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```ts
|
|
182
|
-
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.map(n => n * 2));
|
|
183
|
-
* // ReadonlyMap { "a" => 2, "b" => 4 }
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
const map: <A, B>(f: (a: A) => B) => <K>(m: ReadonlyMap<K, A>) => ReadonlyMap<K, B>;
|
|
187
|
-
/**
|
|
188
|
-
* Transforms each value in the dictionary, also receiving the key.
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```ts
|
|
192
|
-
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.mapWithKey((k, v) => `${k}:${v}`));
|
|
193
|
-
* // ReadonlyMap { "a" => "a:1", "b" => "b:2" }
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
const mapWithKey: <K, A, B>(f: (key: K, a: A) => B) => (m: ReadonlyMap<K, A>) => ReadonlyMap<K, B>;
|
|
197
|
-
/**
|
|
198
|
-
* Returns a new dictionary containing only the entries for which the predicate returns `true`.
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```ts
|
|
202
|
-
* pipe(Dict.fromEntries([["a", 1], ["b", 3], ["c", 0]]), Dict.filter(n => n > 0));
|
|
203
|
-
* // ReadonlyMap { "a" => 1, "b" => 3 }
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
const filter: <A>(predicate: (a: A) => boolean) => <K>(m: ReadonlyMap<K, A>) => ReadonlyMap<K, A>;
|
|
207
|
-
/**
|
|
208
|
-
* Returns a new dictionary containing only the entries for which the predicate returns `true`.
|
|
209
|
-
* The predicate also receives the key.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
214
|
-
* // ReadonlyMap { "b" => 2 }
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
const filterWithKey: <K, A>(predicate: (key: K, a: A) => boolean) => (m: ReadonlyMap<K, A>) => ReadonlyMap<K, A>;
|
|
218
|
-
/**
|
|
219
|
-
* Removes all `None` values from a `ReadonlyMap<K, Option<A>>`, returning a plain
|
|
220
|
-
* `ReadonlyMap<K, A>`. Useful when building dictionaries from fallible lookups.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```ts
|
|
224
|
-
* import { Option } from "@nlozgachev/pipelined/core";
|
|
225
|
-
*
|
|
226
|
-
* Dict.compact(Dict.fromEntries([
|
|
227
|
-
* ["a", Option.some(1)],
|
|
228
|
-
* ["b", Option.none()],
|
|
229
|
-
* ["c", Option.some(3)],
|
|
230
|
-
* ]));
|
|
231
|
-
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
const compact: <K, A>(m: ReadonlyMap<K, Option<A>>) => ReadonlyMap<K, A>;
|
|
235
|
-
/**
|
|
236
|
-
* Merges two dictionaries. When both contain the same key, the value from `other` takes
|
|
237
|
-
* precedence.
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```ts
|
|
241
|
-
* pipe(
|
|
242
|
-
* Dict.fromEntries([["a", 1], ["b", 2]]),
|
|
243
|
-
* Dict.union(Dict.fromEntries([["b", 3], ["c", 4]])),
|
|
244
|
-
* );
|
|
245
|
-
* // ReadonlyMap { "a" => 1, "b" => 3, "c" => 4 }
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
const union: <K, V>(other: ReadonlyMap<K, V>) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
249
|
-
/**
|
|
250
|
-
* Returns a new dictionary containing only the entries whose keys appear in both dictionaries.
|
|
251
|
-
* Values are taken from the left (base) dictionary.
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```ts
|
|
255
|
-
* pipe(
|
|
256
|
-
* Dict.fromEntries([["a", 1], ["b", 2], ["c", 3]]),
|
|
257
|
-
* Dict.intersection(Dict.fromEntries([["b", 99], ["c", 0]])),
|
|
258
|
-
* );
|
|
259
|
-
* // ReadonlyMap { "b" => 2, "c" => 3 }
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
const intersection: <K, V>(other: ReadonlyMap<K, unknown>) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
263
|
-
/**
|
|
264
|
-
* Returns a new dictionary containing only the entries whose keys do not appear in `other`.
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```ts
|
|
268
|
-
* pipe(
|
|
269
|
-
* Dict.fromEntries([["a", 1], ["b", 2], ["c", 3]]),
|
|
270
|
-
* Dict.difference(Dict.fromEntries([["b", 0]])),
|
|
271
|
-
* );
|
|
272
|
-
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
const difference: <K, V>(other: ReadonlyMap<K, unknown>) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
276
|
-
/**
|
|
277
|
-
* Folds the dictionary into a single value by applying `f` to each value in insertion order.
|
|
278
|
-
* When you also need the key, use `reduceWithKey`.
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```ts
|
|
282
|
-
* Dict.reduce(0, (acc, value) => acc + value)(
|
|
283
|
-
* Dict.fromEntries([["a", 1], ["b", 2], ["c", 3]])
|
|
284
|
-
* ); // 6
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
const reduce: <A, B>(init: B, f: (acc: B, value: A) => B) => <K>(m: ReadonlyMap<K, A>) => B;
|
|
288
|
-
/**
|
|
289
|
-
* Folds the dictionary into a single value by applying `f` to each key-value pair in insertion
|
|
290
|
-
* order.
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* ```ts
|
|
294
|
-
* Dict.reduceWithKey("", (acc, value, key) => acc + key + ":" + value + " ")(
|
|
295
|
-
* Dict.fromEntries([["a", 1], ["b", 2]])
|
|
296
|
-
* ); // "a:1 b:2 "
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
const reduceWithKey: <K, A, B>(init: B, f: (acc: B, value: A, key: K) => B) => (m: ReadonlyMap<K, A>) => B;
|
|
300
|
-
/**
|
|
301
|
-
* Converts a `ReadonlyMap<string, V>` to a plain object. Only meaningful when keys are strings.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```ts
|
|
305
|
-
* Dict.toRecord(Dict.fromEntries([["a", 1], ["b", 2]])); // { a: 1, b: 2 }
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
const toRecord: <V>(m: ReadonlyMap<string, V>) => Readonly<Record<string, V>>;
|
|
309
|
-
}
|
|
310
|
-
//# sourceMappingURL=Dict.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Dict.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/Dict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,yBAAiB,IAAI,CAAC;IAKrB;;;;;;;OAOG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,O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,CAAC;IAEF;;;;;;;;;;;;OAYG;IACI,MAAM,YAAY,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAM7G,CAAC;IAEF;;;;;;;;;;;OAWG;IACI,MAAM,UAAU,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAM3G,CAAC;IAMF;;;;;;;;;;OAUG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAM/F,CAAC;IAEF;;;;;;;;;;OAUG;IACI,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAM9G,CAAC;IAMF;;;;;;;OAOG;IACI,MAAM,QAAQ,GAAI,CAAC,EAAE,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAA0B,CAAC;CAC7G"}
|
package/types/src/Utils/Num.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Option } from "../Core/Option.js";
|
|
2
|
-
/**
|
|
3
|
-
* Number utilities for common operations. All transformation functions are data-last
|
|
4
|
-
* and curried so they compose naturally with `pipe` and `Arr.map`.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { Num } from "@nlozgachev/pipelined/utils";
|
|
9
|
-
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
10
|
-
*
|
|
11
|
-
* pipe(
|
|
12
|
-
* Num.range(1, 6),
|
|
13
|
-
* Arr.map(Num.multiply(2)),
|
|
14
|
-
* Arr.filter(Num.between(4, 8))
|
|
15
|
-
* ); // [4, 6, 8]
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare namespace Num {
|
|
19
|
-
/**
|
|
20
|
-
* Generates an array of numbers from `from` to `to` (both inclusive),
|
|
21
|
-
* stepping by `step` (default `1`). If `step` is negative or zero, or `from > to`,
|
|
22
|
-
* returns an empty array. When `step` does not land exactly on `to`, the last value
|
|
23
|
-
* is the largest reachable value that does not exceed `to`.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* Num.range(0, 5); // [0, 1, 2, 3, 4, 5]
|
|
28
|
-
* Num.range(0, 10, 2); // [0, 2, 4, 6, 8, 10]
|
|
29
|
-
* Num.range(0, 9, 2); // [0, 2, 4, 6, 8]
|
|
30
|
-
* Num.range(5, 0); // []
|
|
31
|
-
* Num.range(3, 3); // [3]
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
const range: (from: number, to: number, step?: number) => readonly number[];
|
|
35
|
-
/**
|
|
36
|
-
* Clamps a number between `min` and `max` (both inclusive).
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* pipe(150, Num.clamp(0, 100)); // 100
|
|
41
|
-
* pipe(-5, Num.clamp(0, 100)); // 0
|
|
42
|
-
* pipe(42, Num.clamp(0, 100)); // 42
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
const clamp: (min: number, max: number) => (n: number) => number;
|
|
46
|
-
/**
|
|
47
|
-
* Returns `true` when the number is between `min` and `max` (both inclusive).
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* pipe(5, Num.between(1, 10)); // true
|
|
52
|
-
* pipe(0, Num.between(1, 10)); // false
|
|
53
|
-
* pipe(10, Num.between(1, 10)); // true
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
const between: (min: number, max: number) => (n: number) => boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Parses a string as a number. Returns `None` when the result is `NaN`.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* Num.parse("42"); // Some(42)
|
|
63
|
-
* Num.parse("3.14"); // Some(3.14)
|
|
64
|
-
* Num.parse("abc"); // None
|
|
65
|
-
* Num.parse(""); // None
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
const parse: (s: string) => Option<number>;
|
|
69
|
-
/**
|
|
70
|
-
* Adds `b` to a number. Data-last: use in `pipe` or `Arr.map`.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```ts
|
|
74
|
-
* pipe(5, Num.add(3)); // 8
|
|
75
|
-
* pipe([1, 2, 3], Arr.map(Num.add(10))); // [11, 12, 13]
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
const add: (b: number) => (a: number) => number;
|
|
79
|
-
/**
|
|
80
|
-
* Subtracts `b` from a number. Data-last: `subtract(b)(a)` = `a - b`.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* pipe(10, Num.subtract(3)); // 7
|
|
85
|
-
* pipe([5, 10, 15], Arr.map(Num.subtract(2))); // [3, 8, 13]
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
const subtract: (b: number) => (a: number) => number;
|
|
89
|
-
/**
|
|
90
|
-
* Multiplies a number by `b`. Data-last: use in `pipe` or `Arr.map`.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* pipe(6, Num.multiply(7)); // 42
|
|
95
|
-
* pipe([1, 2, 3], Arr.map(Num.multiply(100))); // [100, 200, 300]
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
const multiply: (b: number) => (a: number) => number;
|
|
99
|
-
/**
|
|
100
|
-
* Divides a number by `b`. Data-last: `divide(b)(a)` = `a / b`.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* pipe(20, Num.divide(4)); // 5
|
|
105
|
-
* pipe([10, 20, 30], Arr.map(Num.divide(10))); // [1, 2, 3]
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
const divide: (b: number) => (a: number) => number;
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=Num.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Num.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/Num.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,yBAAiB,GAAG,CAAC;IACpB;;;;;;;;;;;;;;OAcG;IACI,MAAM,KAAK,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM,EAAE,aAAQ,KAAG,SAAS,MAAM,EAQzE,CAAC;IAEF;;;;;;;;;OASG;IACI,MAAM,KAAK,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,MAAM,GAAG,MAAM,KAAG,MAAyC,CAAC;IAE1G;;;;;;;;;OASG;IACI,MAAM,OAAO,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,MAAM,GAAG,MAAM,KAAG,OAA+B,CAAC;IAElG;;;;;;;;;;OAUG;IACI,MAAM,KAAK,GAAI,GAAG,MAAM,KAAG,MAAM,CAAC,MAAM,CAI9C,CAAC;IAEF;;;;;;;;OAQG;IACI,MAAM,GAAG,GAAI,GAAG,MAAM,MAAM,GAAG,MAAM,KAAG,MAAe,CAAC;IAE/D;;;;;;;;OAQG;IACI,MAAM,QAAQ,GAAI,GAAG,MAAM,MAAM,GAAG,MAAM,KAAG,MAAe,CAAC;IAEpE;;;;;;;;OAQG;IACI,MAAM,QAAQ,GAAI,GAAG,MAAM,MAAM,GAAG,MAAM,KAAG,MAAe,CAAC;IAEpE;;;;;;;;OAQG;IACI,MAAM,MAAM,GAAI,GAAG,MAAM,MAAM,GAAG,MAAM,KAAG,MAAe,CAAC;CAClE"}
|
package/types/src/Utils/Rec.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { Option } from "../Core/Option.js";
|
|
2
|
-
/**
|
|
3
|
-
* Functional record/object utilities that compose well with pipe.
|
|
4
|
-
* All functions are data-last and curried where applicable.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* pipe(
|
|
9
|
-
* { a: 1, b: 2, c: 3 },
|
|
10
|
-
* Rec.filter(n => n > 1),
|
|
11
|
-
* Rec.map(n => n * 10)
|
|
12
|
-
* ); // { b: 20, c: 30 }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export declare namespace Rec {
|
|
16
|
-
/**
|
|
17
|
-
* Transforms each value in a record.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* pipe({ a: 1, b: 2 }, Rec.map(n => n * 2)); // { a: 2, b: 4 }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
const map: <A, B>(f: (a: A) => B) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
|
|
25
|
-
/**
|
|
26
|
-
* Transforms each value in a record, also receiving the key.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* pipe({ a: 1, b: 2 }, Rec.mapWithKey((k, v) => `${k}:${v}`));
|
|
31
|
-
* // { a: "a:1", b: "b:2" }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
const mapWithKey: <A, B>(f: (key: string, a: A) => B) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
|
|
35
|
-
/**
|
|
36
|
-
* Filters values in a record by a predicate.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* pipe({ a: 1, b: 2, c: 3 }, Rec.filter(n => n > 1)); // { b: 2, c: 3 }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
const filter: <A>(predicate: (a: A) => boolean) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, A>>;
|
|
44
|
-
/**
|
|
45
|
-
* Filters values in a record by a predicate that also receives the key.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* pipe({ a: 1, b: 2 }, Rec.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
50
|
-
* // { b: 2 }
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
const filterWithKey: <A>(predicate: (key: string, a: A) => boolean) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, A>>;
|
|
54
|
-
/**
|
|
55
|
-
* Looks up a value by key, returning Option.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* pipe({ a: 1, b: 2 }, Rec.lookup("a")); // Some(1)
|
|
60
|
-
* pipe({ a: 1, b: 2 }, Rec.lookup("c")); // None
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
const lookup: (key: string) => <A>(data: Readonly<Record<string, A>>) => Option<A>;
|
|
64
|
-
/**
|
|
65
|
-
* Returns all keys of a record.
|
|
66
|
-
*/
|
|
67
|
-
const keys: <A>(data: Readonly<Record<string, A>>) => readonly string[];
|
|
68
|
-
/**
|
|
69
|
-
* Returns all values of a record.
|
|
70
|
-
*/
|
|
71
|
-
const values: <A>(data: Readonly<Record<string, A>>) => readonly A[];
|
|
72
|
-
/**
|
|
73
|
-
* Returns all key-value pairs of a record.
|
|
74
|
-
*/
|
|
75
|
-
const entries: <A>(data: Readonly<Record<string, A>>) => readonly (readonly [string, A])[];
|
|
76
|
-
/**
|
|
77
|
-
* Creates a record from key-value pairs.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* Rec.fromEntries([["a", 1], ["b", 2]]); // { a: 1, b: 2 }
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
const fromEntries: <A>(data: readonly (readonly [string, A])[]) => Readonly<Record<string, A>>;
|
|
85
|
-
/**
|
|
86
|
-
* Groups elements of an array into a record keyed by the result of `keyFn`. Each key maps to
|
|
87
|
-
* the array of elements that produced it, in insertion order.
|
|
88
|
-
*
|
|
89
|
-
* Unlike `Dict.groupBy`, keys are always strings. Use `Dict.groupBy` when you need non-string
|
|
90
|
-
* keys or want to avoid the plain-object prototype chain.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* pipe(
|
|
95
|
-
* ["apple", "avocado", "banana", "blueberry"],
|
|
96
|
-
* Rec.groupBy(s => s[0]),
|
|
97
|
-
* ); // { a: ["apple", "avocado"], b: ["banana", "blueberry"] }
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
const groupBy: <A>(keyFn: (a: A) => string) => (items: readonly A[]) => Readonly<Record<string, readonly A[]>>;
|
|
101
|
-
/**
|
|
102
|
-
* Picks specific keys from a record.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```ts
|
|
106
|
-
* pipe({ a: 1, b: 2, c: 3 }, Rec.pick("a", "c")); // { a: 1, c: 3 }
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
const pick: <K extends string>(...pickedKeys: K[]) => <A extends Record<K, unknown>>(data: A) => Pick<A, K>;
|
|
110
|
-
/**
|
|
111
|
-
* Omits specific keys from a record.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* pipe({ a: 1, b: 2, c: 3 }, Rec.omit("b")); // { a: 1, c: 3 }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
const omit: <K extends string>(...omittedKeys: K[]) => <A extends Record<K, unknown>>(data: A) => Omit<A, K>;
|
|
119
|
-
/**
|
|
120
|
-
* Merges two records. Values from the second record take precedence.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* pipe({ a: 1, b: 2 }, Rec.merge({ b: 3, c: 4 })); // { a: 1, b: 3, c: 4 }
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
const merge: <A>(other: Readonly<Record<string, A>>) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, A>>;
|
|
128
|
-
/**
|
|
129
|
-
* Returns true if the record has no keys.
|
|
130
|
-
*/
|
|
131
|
-
const isEmpty: <A>(data: Readonly<Record<string, A>>) => boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Returns the number of keys in a record.
|
|
134
|
-
*/
|
|
135
|
-
const size: <A>(data: Readonly<Record<string, A>>) => number;
|
|
136
|
-
/**
|
|
137
|
-
* Transforms each key while preserving values.
|
|
138
|
-
* If two keys map to the same new key, the last one wins.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```ts
|
|
142
|
-
* pipe({ firstName: "Alice", lastName: "Smith" }, Rec.mapKeys(k => k.toUpperCase()));
|
|
143
|
-
* // { FIRSTNAME: "Alice", LASTNAME: "Smith" }
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
const mapKeys: (f: (key: string) => string) => <A>(data: Readonly<Record<string, A>>) => Readonly<Record<string, A>>;
|
|
147
|
-
/**
|
|
148
|
-
* Removes all `None` values from a `Record<string, Option<A>>`, returning a plain `Record<string, A>`.
|
|
149
|
-
* Useful when building records from fallible lookups.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```ts
|
|
153
|
-
* Rec.compact({ a: Option.some(1), b: Option.none(), c: Option.some(3) });
|
|
154
|
-
* // { a: 1, c: 3 }
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
const compact: <A>(data: Readonly<Record<string, Option<A>>>) => Readonly<Record<string, A>>;
|
|
158
|
-
}
|
|
159
|
-
//# sourceMappingURL=Rec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Rec.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/Rec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,yBAAiB,GAAG,CAAC;IACpB;;;;;;;OAOG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAQ3G,CAAC;IAEF;;;;;;;;OAQG;IACI,MAAM,UAAU,GACrB,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAQrG,CAAC;IAEH;;;;;;;OAOG;IACI,MAAM,MAAM,GACjB,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,MAAM,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAQnG,CAAC;IAE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