effect 2.4.16 → 2.4.17
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/Iterable/package.json +6 -0
- package/dist/cjs/Effect.js +11 -4
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Inspectable.js +23 -1
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/Iterable.js +938 -0
- package/dist/cjs/Iterable.js.map +1 -0
- package/dist/cjs/ReadonlyArray.js +2 -17
- package/dist/cjs/ReadonlyArray.js.map +1 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +3 -2
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +8 -22
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/runtime.js +42 -50
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/schedule.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Config.d.ts +2 -2
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +30 -20
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Inspectable.d.ts +8 -0
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +495 -0
- package/dist/dts/Iterable.d.ts.map +1 -0
- package/dist/dts/ReadonlyArray.d.ts.map +1 -1
- package/dist/dts/index.d.ts +6 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/logger.d.ts +0 -1
- package/dist/dts/internal/logger.d.ts.map +1 -1
- package/dist/esm/Effect.js +7 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Inspectable.js +20 -0
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/Iterable.js +893 -0
- package/dist/esm/Iterable.js.map +1 -0
- package/dist/esm/ReadonlyArray.js +2 -17
- package/dist/esm/ReadonlyArray.js.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +3 -2
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +6 -19
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/runtime.js +42 -50
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/schedule.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +9 -1
- package/src/Config.ts +2 -2
- package/src/Effect.ts +64 -47
- package/src/Inspectable.ts +30 -0
- package/src/Iterable.ts +1009 -0
- package/src/ReadonlyArray.ts +2 -20
- package/src/index.ts +7 -0
- package/src/internal/config.ts +2 -2
- package/src/internal/core-effect.ts +11 -9
- package/src/internal/effect/circular.ts +19 -7
- package/src/internal/fiberRuntime.ts +47 -29
- package/src/internal/logger.ts +6 -28
- package/src/internal/runtime.ts +45 -52
- package/src/internal/schedule.ts +3 -3
- package/src/internal/version.ts +1 -1
|
@@ -0,0 +1,938 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.zipWith = exports.zip = exports.unfold = exports.takeWhile = exports.take = exports.some = exports.size = exports.scan = exports.replicate = exports.range = exports.prependAll = exports.prepend = exports.of = exports.map = exports.makeBy = exports.isEmpty = exports.intersperse = exports.head = exports.groupWith = exports.groupBy = exports.group = exports.getSomes = exports.getRights = exports.getLefts = exports.fromRecord = exports.forEach = exports.flatten = exports.flatMapNullable = exports.flatMap = exports.findLast = exports.findFirst = exports.filterMapWhile = exports.filterMap = exports.filter = exports.empty = exports.drop = exports.dedupeAdjacentWith = exports.dedupeAdjacent = exports.containsWith = exports.contains = exports.chunksOf = exports.cartesianWith = exports.cartesian = exports.appendAll = exports.append = void 0;
|
|
7
|
+
var E = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Either.js"));
|
|
8
|
+
var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Equal.js"));
|
|
9
|
+
var _Function = /*#__PURE__*/require("./Function.js");
|
|
10
|
+
var O = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Option.js"));
|
|
11
|
+
var _Predicate = /*#__PURE__*/require("./Predicate.js");
|
|
12
|
+
var Tuple = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Tuple.js"));
|
|
13
|
+
function _getRequireWildcardCache(e) {
|
|
14
|
+
if ("function" != typeof WeakMap) return null;
|
|
15
|
+
var r = new WeakMap(),
|
|
16
|
+
t = new WeakMap();
|
|
17
|
+
return (_getRequireWildcardCache = function (e) {
|
|
18
|
+
return e ? t : r;
|
|
19
|
+
})(e);
|
|
20
|
+
}
|
|
21
|
+
function _interopRequireWildcard(e, r) {
|
|
22
|
+
if (!r && e && e.__esModule) return e;
|
|
23
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return {
|
|
24
|
+
default: e
|
|
25
|
+
};
|
|
26
|
+
var t = _getRequireWildcardCache(r);
|
|
27
|
+
if (t && t.has(e)) return t.get(e);
|
|
28
|
+
var n = {
|
|
29
|
+
__proto__: null
|
|
30
|
+
},
|
|
31
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
32
|
+
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
33
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
34
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
35
|
+
}
|
|
36
|
+
return n.default = e, t && t.set(e, n), n;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* This module provides utility functions for working with Iterables in TypeScript.
|
|
40
|
+
*
|
|
41
|
+
* @since 2.0.0
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return a `Iterable` with element `i` initialized with `f(i)`.
|
|
46
|
+
*
|
|
47
|
+
* If the `length` is not specified, the `Iterable` will be infinite.
|
|
48
|
+
*
|
|
49
|
+
* **Note**. `length` is normalized to an integer >= 1.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* import { makeBy } from 'effect/Iterable'
|
|
53
|
+
*
|
|
54
|
+
* assert.deepStrictEqual(Array.from(makeBy(n => n * 2, { length: 5 })), [0, 2, 4, 6, 8])
|
|
55
|
+
*
|
|
56
|
+
* @category constructors
|
|
57
|
+
* @since 2.0.0
|
|
58
|
+
*/
|
|
59
|
+
const makeBy = (f, options) => {
|
|
60
|
+
const max = options?.length !== undefined ? Math.max(1, Math.floor(options.length)) : Infinity;
|
|
61
|
+
return {
|
|
62
|
+
[Symbol.iterator]() {
|
|
63
|
+
let i = 0;
|
|
64
|
+
return {
|
|
65
|
+
next() {
|
|
66
|
+
if (i < max) {
|
|
67
|
+
return {
|
|
68
|
+
value: f(i++),
|
|
69
|
+
done: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
done: true,
|
|
74
|
+
value: undefined
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Return a `Iterable` containing a range of integers, including both endpoints.
|
|
83
|
+
*
|
|
84
|
+
* If `end` is omitted, the range will not have an upper bound.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* import { range } from 'effect/Iterable'
|
|
88
|
+
*
|
|
89
|
+
* assert.deepStrictEqual(Array.from(range(1, 3)), [1, 2, 3])
|
|
90
|
+
*
|
|
91
|
+
* @category constructors
|
|
92
|
+
* @since 2.0.0
|
|
93
|
+
*/
|
|
94
|
+
exports.makeBy = makeBy;
|
|
95
|
+
const range = (start, end) => {
|
|
96
|
+
if (end === undefined) {
|
|
97
|
+
return makeBy(i => start + i);
|
|
98
|
+
}
|
|
99
|
+
return makeBy(i => start + i, {
|
|
100
|
+
length: start <= end ? end - start + 1 : 1
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Return a `Iterable` containing a value repeated the specified number of times.
|
|
105
|
+
*
|
|
106
|
+
* **Note**. `n` is normalized to an integer >= 1.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* import { replicate } from 'effect/Iterable'
|
|
110
|
+
*
|
|
111
|
+
* assert.deepStrictEqual(Array.from(replicate("a", 3)), ["a", "a", "a"])
|
|
112
|
+
*
|
|
113
|
+
* @category constructors
|
|
114
|
+
* @since 2.0.0
|
|
115
|
+
*/
|
|
116
|
+
exports.range = range;
|
|
117
|
+
const replicate = exports.replicate = /*#__PURE__*/(0, _Function.dual)(2, (a, n) => makeBy(() => a, {
|
|
118
|
+
length: n
|
|
119
|
+
}));
|
|
120
|
+
/**
|
|
121
|
+
* Takes a record and returns an Iterable of tuples containing its keys and values.
|
|
122
|
+
*
|
|
123
|
+
* @param self - The record to transform.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* import { fromRecord } from "effect/Iterable"
|
|
127
|
+
*
|
|
128
|
+
* const x = { a: 1, b: 2, c: 3 }
|
|
129
|
+
* assert.deepStrictEqual(Array.from(fromRecord(x)), [["a", 1], ["b", 2], ["c", 3]])
|
|
130
|
+
*
|
|
131
|
+
* @category conversions
|
|
132
|
+
* @since 2.0.0
|
|
133
|
+
*/
|
|
134
|
+
const fromRecord = self => ({
|
|
135
|
+
*[Symbol.iterator]() {
|
|
136
|
+
for (const key in self) {
|
|
137
|
+
if (Object.prototype.hasOwnProperty.call(self, key)) {
|
|
138
|
+
yield [key, self[key]];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Prepend an element to the front of an `Iterable`, creating a new `Iterable`.
|
|
145
|
+
*
|
|
146
|
+
* @category concatenating
|
|
147
|
+
* @since 2.0.0
|
|
148
|
+
*/
|
|
149
|
+
exports.fromRecord = fromRecord;
|
|
150
|
+
const prepend = exports.prepend = /*#__PURE__*/(0, _Function.dual)(2, (self, head) => flatten([[head], self]));
|
|
151
|
+
/**
|
|
152
|
+
* Prepends the specified prefix iterable to the beginning of the specified iterable.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* import * as Iterable from "effect/Iterable"
|
|
156
|
+
*
|
|
157
|
+
* assert.deepStrictEqual(
|
|
158
|
+
* Array.from(Iterable.prependAll([1, 2], ["a", "b"])),
|
|
159
|
+
* ["a", "b", 1, 2]
|
|
160
|
+
* )
|
|
161
|
+
*
|
|
162
|
+
* @category concatenating
|
|
163
|
+
* @since 2.0.0
|
|
164
|
+
*/
|
|
165
|
+
const prependAll = exports.prependAll = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatten([that, self]));
|
|
166
|
+
/**
|
|
167
|
+
* Append an element to the end of an `Iterable`, creating a new `Iterable`.
|
|
168
|
+
*
|
|
169
|
+
* @category concatenating
|
|
170
|
+
* @since 2.0.0
|
|
171
|
+
*/
|
|
172
|
+
const append = exports.append = /*#__PURE__*/(0, _Function.dual)(2, (self, last) => flatten([self, [last]]));
|
|
173
|
+
/**
|
|
174
|
+
* Concatenates two iterables, combining their elements.
|
|
175
|
+
*
|
|
176
|
+
* @category concatenating
|
|
177
|
+
* @since 2.0.0
|
|
178
|
+
*/
|
|
179
|
+
const appendAll = exports.appendAll = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => flatten([self, that]));
|
|
180
|
+
/**
|
|
181
|
+
* Reduce an `Iterable` from the left, keeping all intermediate results instead of only the final result.
|
|
182
|
+
*
|
|
183
|
+
* @category folding
|
|
184
|
+
* @since 2.0.0
|
|
185
|
+
*/
|
|
186
|
+
const scan = exports.scan = /*#__PURE__*/(0, _Function.dual)(3, (self, b, f) => ({
|
|
187
|
+
[Symbol.iterator]() {
|
|
188
|
+
let acc = b;
|
|
189
|
+
let iterator;
|
|
190
|
+
function next() {
|
|
191
|
+
if (iterator === undefined) {
|
|
192
|
+
iterator = self[Symbol.iterator]();
|
|
193
|
+
return {
|
|
194
|
+
done: false,
|
|
195
|
+
value: acc
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const result = iterator.next();
|
|
199
|
+
if (result.done) {
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
acc = f(acc, result.value);
|
|
203
|
+
return {
|
|
204
|
+
done: false,
|
|
205
|
+
value: acc
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
next
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}));
|
|
213
|
+
/**
|
|
214
|
+
* Determine if an `Iterable` is empty
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* import { isEmpty } from "effect/Iterable"
|
|
218
|
+
*
|
|
219
|
+
* assert.deepStrictEqual(isEmpty([]), true);
|
|
220
|
+
* assert.deepStrictEqual(isEmpty([1, 2, 3]), false);
|
|
221
|
+
*
|
|
222
|
+
* @category guards
|
|
223
|
+
* @since 2.0.0
|
|
224
|
+
*/
|
|
225
|
+
const isEmpty = self => {
|
|
226
|
+
const iterator = self[Symbol.iterator]();
|
|
227
|
+
return iterator.next().done === true;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Return the number of elements in a `Iterable`.
|
|
231
|
+
*
|
|
232
|
+
* @category getters
|
|
233
|
+
* @since 2.0.0
|
|
234
|
+
*/
|
|
235
|
+
exports.isEmpty = isEmpty;
|
|
236
|
+
const size = self => {
|
|
237
|
+
const iterator = self[Symbol.iterator]();
|
|
238
|
+
let count = 0;
|
|
239
|
+
while (!iterator.next().done) {
|
|
240
|
+
count++;
|
|
241
|
+
}
|
|
242
|
+
return count;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Get the first element of a `Iterable`, or `None` if the `Iterable` is empty.
|
|
246
|
+
*
|
|
247
|
+
* @category getters
|
|
248
|
+
* @since 2.0.0
|
|
249
|
+
*/
|
|
250
|
+
exports.size = size;
|
|
251
|
+
const head = self => {
|
|
252
|
+
const iterator = self[Symbol.iterator]();
|
|
253
|
+
const result = iterator.next();
|
|
254
|
+
return result.done ? O.none() : O.some(result.value);
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Keep only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.
|
|
258
|
+
*
|
|
259
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
260
|
+
*
|
|
261
|
+
* @category getters
|
|
262
|
+
* @since 2.0.0
|
|
263
|
+
*/
|
|
264
|
+
exports.head = head;
|
|
265
|
+
const take = exports.take = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => ({
|
|
266
|
+
[Symbol.iterator]() {
|
|
267
|
+
let i = 0;
|
|
268
|
+
const iterator = self[Symbol.iterator]();
|
|
269
|
+
return {
|
|
270
|
+
next() {
|
|
271
|
+
if (i < n) {
|
|
272
|
+
i++;
|
|
273
|
+
return iterator.next();
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
done: true,
|
|
277
|
+
value: undefined
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}));
|
|
283
|
+
/**
|
|
284
|
+
* Calculate the longest initial Iterable for which all element satisfy the specified predicate, creating a new `Iterable`.
|
|
285
|
+
*
|
|
286
|
+
* @category getters
|
|
287
|
+
* @since 2.0.0
|
|
288
|
+
*/
|
|
289
|
+
const takeWhile = exports.takeWhile = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => ({
|
|
290
|
+
[Symbol.iterator]() {
|
|
291
|
+
const iterator = self[Symbol.iterator]();
|
|
292
|
+
let i = 0;
|
|
293
|
+
return {
|
|
294
|
+
next() {
|
|
295
|
+
const result = iterator.next();
|
|
296
|
+
if (result.done || !predicate(result.value, i++)) {
|
|
297
|
+
return {
|
|
298
|
+
done: true,
|
|
299
|
+
value: undefined
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}));
|
|
307
|
+
/**
|
|
308
|
+
* Drop a max number of elements from the start of an `Iterable`
|
|
309
|
+
*
|
|
310
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
311
|
+
*
|
|
312
|
+
* @category getters
|
|
313
|
+
* @since 2.0.0
|
|
314
|
+
*/
|
|
315
|
+
const drop = exports.drop = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => ({
|
|
316
|
+
[Symbol.iterator]() {
|
|
317
|
+
const iterator = self[Symbol.iterator]();
|
|
318
|
+
let i = 0;
|
|
319
|
+
return {
|
|
320
|
+
next() {
|
|
321
|
+
while (i < n) {
|
|
322
|
+
const result = iterator.next();
|
|
323
|
+
if (result.done) {
|
|
324
|
+
return {
|
|
325
|
+
done: true,
|
|
326
|
+
value: undefined
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
i++;
|
|
330
|
+
}
|
|
331
|
+
return iterator.next();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}));
|
|
336
|
+
/**
|
|
337
|
+
* Returns the first element that satisfies the specified
|
|
338
|
+
* predicate, or `None` if no such element exists.
|
|
339
|
+
*
|
|
340
|
+
* @category elements
|
|
341
|
+
* @since 2.0.0
|
|
342
|
+
*/
|
|
343
|
+
const findFirst = exports.findFirst = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
344
|
+
let i = 0;
|
|
345
|
+
for (const a of self) {
|
|
346
|
+
const o = f(a, i);
|
|
347
|
+
if ((0, _Predicate.isBoolean)(o)) {
|
|
348
|
+
if (o) {
|
|
349
|
+
return O.some(a);
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
if (O.isSome(o)) {
|
|
353
|
+
return o;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
i++;
|
|
357
|
+
}
|
|
358
|
+
return O.none();
|
|
359
|
+
});
|
|
360
|
+
/**
|
|
361
|
+
* Find the last element for which a predicate holds.
|
|
362
|
+
*
|
|
363
|
+
* @category elements
|
|
364
|
+
* @since 2.0.0
|
|
365
|
+
*/
|
|
366
|
+
const findLast = exports.findLast = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
367
|
+
let i = 0;
|
|
368
|
+
let last = O.none();
|
|
369
|
+
for (const a of self) {
|
|
370
|
+
const o = f(a, i);
|
|
371
|
+
if ((0, _Predicate.isBoolean)(o)) {
|
|
372
|
+
if (o) {
|
|
373
|
+
last = O.some(a);
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
if (O.isSome(o)) {
|
|
377
|
+
last = o;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
i++;
|
|
381
|
+
}
|
|
382
|
+
return last;
|
|
383
|
+
});
|
|
384
|
+
/**
|
|
385
|
+
* Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.
|
|
386
|
+
*
|
|
387
|
+
* @category zipping
|
|
388
|
+
* @since 2.0.0
|
|
389
|
+
*/
|
|
390
|
+
const zip = exports.zip = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => zipWith(self, that, Tuple.make));
|
|
391
|
+
/**
|
|
392
|
+
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one
|
|
393
|
+
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
394
|
+
*
|
|
395
|
+
* @category zipping
|
|
396
|
+
* @since 2.0.0
|
|
397
|
+
*/
|
|
398
|
+
const zipWith = exports.zipWith = /*#__PURE__*/(0, _Function.dual)(3, (self, that, f) => ({
|
|
399
|
+
[Symbol.iterator]() {
|
|
400
|
+
const selfIterator = self[Symbol.iterator]();
|
|
401
|
+
const thatIterator = that[Symbol.iterator]();
|
|
402
|
+
return {
|
|
403
|
+
next() {
|
|
404
|
+
const selfResult = selfIterator.next();
|
|
405
|
+
const thatResult = thatIterator.next();
|
|
406
|
+
if (selfResult.done || thatResult.done) {
|
|
407
|
+
return {
|
|
408
|
+
done: true,
|
|
409
|
+
value: undefined
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
done: false,
|
|
414
|
+
value: f(selfResult.value, thatResult.value)
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
}));
|
|
420
|
+
/**
|
|
421
|
+
* Places an element in between members of an `Iterable`.
|
|
422
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
423
|
+
*
|
|
424
|
+
* @since 2.0.0
|
|
425
|
+
*/
|
|
426
|
+
const intersperse = exports.intersperse = /*#__PURE__*/(0, _Function.dual)(2, (self, middle) => ({
|
|
427
|
+
[Symbol.iterator]() {
|
|
428
|
+
const iterator = self[Symbol.iterator]();
|
|
429
|
+
let next = iterator.next();
|
|
430
|
+
let emitted = false;
|
|
431
|
+
return {
|
|
432
|
+
next() {
|
|
433
|
+
if (next.done) {
|
|
434
|
+
return next;
|
|
435
|
+
} else if (emitted) {
|
|
436
|
+
emitted = false;
|
|
437
|
+
return {
|
|
438
|
+
done: false,
|
|
439
|
+
value: middle
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
emitted = true;
|
|
443
|
+
const result = next;
|
|
444
|
+
next = iterator.next();
|
|
445
|
+
return result;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}));
|
|
450
|
+
/**
|
|
451
|
+
* Returns a function that checks if an `Iterable` contains a given value using a provided `isEquivalent` function.
|
|
452
|
+
*
|
|
453
|
+
* @category elements
|
|
454
|
+
* @since 2.0.0
|
|
455
|
+
*/
|
|
456
|
+
const containsWith = isEquivalent => (0, _Function.dual)(2, (self, a) => {
|
|
457
|
+
for (const i of self) {
|
|
458
|
+
if (isEquivalent(a, i)) {
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
});
|
|
464
|
+
exports.containsWith = containsWith;
|
|
465
|
+
const _equivalence = /*#__PURE__*/Equal.equivalence();
|
|
466
|
+
/**
|
|
467
|
+
* Returns a function that checks if a `Iterable` contains a given value using the default `Equivalence`.
|
|
468
|
+
*
|
|
469
|
+
* @category elements
|
|
470
|
+
* @since 2.0.0
|
|
471
|
+
*/
|
|
472
|
+
const contains = exports.contains = /*#__PURE__*/containsWith(_equivalence);
|
|
473
|
+
/**
|
|
474
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
475
|
+
* the `Iterable`.
|
|
476
|
+
*
|
|
477
|
+
* @category splitting
|
|
478
|
+
* @since 2.0.0
|
|
479
|
+
*/
|
|
480
|
+
const chunksOf = exports.chunksOf = /*#__PURE__*/(0, _Function.dual)(2, (self, n) => {
|
|
481
|
+
const safeN = Math.max(1, Math.floor(n));
|
|
482
|
+
return {
|
|
483
|
+
[Symbol.iterator]() {
|
|
484
|
+
let iterator = self[Symbol.iterator]();
|
|
485
|
+
return {
|
|
486
|
+
next() {
|
|
487
|
+
if (iterator === undefined) {
|
|
488
|
+
return {
|
|
489
|
+
done: true,
|
|
490
|
+
value: undefined
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
const chunk = [];
|
|
494
|
+
for (let i = 0; i < safeN; i++) {
|
|
495
|
+
const result = iterator.next();
|
|
496
|
+
if (result.done) {
|
|
497
|
+
iterator = undefined;
|
|
498
|
+
return chunk.length === 0 ? {
|
|
499
|
+
done: true,
|
|
500
|
+
value: undefined
|
|
501
|
+
} : {
|
|
502
|
+
done: false,
|
|
503
|
+
value: chunk
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
chunk.push(result.value);
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
done: false,
|
|
510
|
+
value: chunk
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
/**
|
|
518
|
+
* Group equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
519
|
+
*
|
|
520
|
+
* @category grouping
|
|
521
|
+
* @since 2.0.0
|
|
522
|
+
*/
|
|
523
|
+
const groupWith = exports.groupWith = /*#__PURE__*/(0, _Function.dual)(2, (self, isEquivalent) => ({
|
|
524
|
+
[Symbol.iterator]() {
|
|
525
|
+
const iterator = self[Symbol.iterator]();
|
|
526
|
+
let nextResult;
|
|
527
|
+
return {
|
|
528
|
+
next() {
|
|
529
|
+
let result;
|
|
530
|
+
if (nextResult !== undefined) {
|
|
531
|
+
if (nextResult.done) {
|
|
532
|
+
return {
|
|
533
|
+
done: true,
|
|
534
|
+
value: undefined
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
result = nextResult;
|
|
538
|
+
nextResult = undefined;
|
|
539
|
+
} else {
|
|
540
|
+
result = iterator.next();
|
|
541
|
+
if (result.done) {
|
|
542
|
+
return {
|
|
543
|
+
done: true,
|
|
544
|
+
value: undefined
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const chunk = [result.value];
|
|
549
|
+
// eslint-disable-next-line no-constant-condition
|
|
550
|
+
while (true) {
|
|
551
|
+
const next = iterator.next();
|
|
552
|
+
if (next.done || !isEquivalent(result.value, next.value)) {
|
|
553
|
+
nextResult = next;
|
|
554
|
+
return {
|
|
555
|
+
done: false,
|
|
556
|
+
value: chunk
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
chunk.push(next.value);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
}));
|
|
565
|
+
/**
|
|
566
|
+
* Group equal, consecutive elements of an `Iterable` into `NonEmptyArray`s.
|
|
567
|
+
*
|
|
568
|
+
* @category grouping
|
|
569
|
+
* @since 2.0.0
|
|
570
|
+
*/
|
|
571
|
+
const group = exports.group = /*#__PURE__*/groupWith( /*#__PURE__*/Equal.equivalence());
|
|
572
|
+
/**
|
|
573
|
+
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
574
|
+
* function on each element, and grouping the results according to values returned
|
|
575
|
+
*
|
|
576
|
+
* @category grouping
|
|
577
|
+
* @since 2.0.0
|
|
578
|
+
*/
|
|
579
|
+
const groupBy = exports.groupBy = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
580
|
+
const out = {};
|
|
581
|
+
for (const a of self) {
|
|
582
|
+
const k = f(a);
|
|
583
|
+
if (Object.prototype.hasOwnProperty.call(out, k)) {
|
|
584
|
+
out[k].push(a);
|
|
585
|
+
} else {
|
|
586
|
+
out[k] = [a];
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return out;
|
|
590
|
+
});
|
|
591
|
+
const constEmpty = {
|
|
592
|
+
[Symbol.iterator]() {
|
|
593
|
+
return constEmptyIterator;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
const constEmptyIterator = {
|
|
597
|
+
next() {
|
|
598
|
+
return {
|
|
599
|
+
done: true,
|
|
600
|
+
value: undefined
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* @category constructors
|
|
606
|
+
* @since 2.0.0
|
|
607
|
+
*/
|
|
608
|
+
const empty = () => constEmpty;
|
|
609
|
+
/**
|
|
610
|
+
* Constructs a new `Iterable<A>` from the specified value.
|
|
611
|
+
*
|
|
612
|
+
* @category constructors
|
|
613
|
+
* @since 2.0.0
|
|
614
|
+
*/
|
|
615
|
+
exports.empty = empty;
|
|
616
|
+
const of = a => [a];
|
|
617
|
+
/**
|
|
618
|
+
* @category mapping
|
|
619
|
+
* @since 2.0.0
|
|
620
|
+
*/
|
|
621
|
+
exports.of = of;
|
|
622
|
+
const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => ({
|
|
623
|
+
[Symbol.iterator]() {
|
|
624
|
+
const iterator = self[Symbol.iterator]();
|
|
625
|
+
let i = 0;
|
|
626
|
+
return {
|
|
627
|
+
next() {
|
|
628
|
+
const result = iterator.next();
|
|
629
|
+
if (result.done) {
|
|
630
|
+
return {
|
|
631
|
+
done: true,
|
|
632
|
+
value: undefined
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
done: false,
|
|
637
|
+
value: f(result.value, i++)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
}));
|
|
643
|
+
/**
|
|
644
|
+
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
|
|
645
|
+
*
|
|
646
|
+
* @category sequencing
|
|
647
|
+
* @since 2.0.0
|
|
648
|
+
*/
|
|
649
|
+
const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => flatten(map(self, f)));
|
|
650
|
+
/**
|
|
651
|
+
* Flattens an Iterable of Iterables into a single Iterable
|
|
652
|
+
*
|
|
653
|
+
* @category sequencing
|
|
654
|
+
* @since 2.0.0
|
|
655
|
+
*/
|
|
656
|
+
const flatten = self => ({
|
|
657
|
+
[Symbol.iterator]() {
|
|
658
|
+
const outerIterator = self[Symbol.iterator]();
|
|
659
|
+
let innerIterator;
|
|
660
|
+
function next() {
|
|
661
|
+
if (innerIterator === undefined) {
|
|
662
|
+
const next = outerIterator.next();
|
|
663
|
+
if (next.done) {
|
|
664
|
+
return next;
|
|
665
|
+
}
|
|
666
|
+
innerIterator = next.value[Symbol.iterator]();
|
|
667
|
+
}
|
|
668
|
+
const result = innerIterator.next();
|
|
669
|
+
if (result.done) {
|
|
670
|
+
innerIterator = undefined;
|
|
671
|
+
return next();
|
|
672
|
+
}
|
|
673
|
+
return result;
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
next
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
/**
|
|
681
|
+
* @category filtering
|
|
682
|
+
* @since 2.0.0
|
|
683
|
+
*/
|
|
684
|
+
exports.flatten = flatten;
|
|
685
|
+
const filterMap = exports.filterMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => ({
|
|
686
|
+
[Symbol.iterator]() {
|
|
687
|
+
const iterator = self[Symbol.iterator]();
|
|
688
|
+
let i = 0;
|
|
689
|
+
return {
|
|
690
|
+
next() {
|
|
691
|
+
let result = iterator.next();
|
|
692
|
+
while (!result.done) {
|
|
693
|
+
const b = f(result.value, i++);
|
|
694
|
+
if (O.isSome(b)) {
|
|
695
|
+
return {
|
|
696
|
+
done: false,
|
|
697
|
+
value: b.value
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
result = iterator.next();
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
done: true,
|
|
704
|
+
value: undefined
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
}));
|
|
710
|
+
/**
|
|
711
|
+
* Transforms all elements of the `Iterable` for as long as the specified function returns some value
|
|
712
|
+
*
|
|
713
|
+
* @category filtering
|
|
714
|
+
* @since 2.0.0
|
|
715
|
+
*/
|
|
716
|
+
const filterMapWhile = exports.filterMapWhile = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => ({
|
|
717
|
+
[Symbol.iterator]() {
|
|
718
|
+
const iterator = self[Symbol.iterator]();
|
|
719
|
+
let i = 0;
|
|
720
|
+
return {
|
|
721
|
+
next() {
|
|
722
|
+
const result = iterator.next();
|
|
723
|
+
if (result.done) {
|
|
724
|
+
return {
|
|
725
|
+
done: true,
|
|
726
|
+
value: undefined
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
const b = f(result.value, i++);
|
|
730
|
+
if (O.isSome(b)) {
|
|
731
|
+
return {
|
|
732
|
+
done: false,
|
|
733
|
+
value: b.value
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
done: true,
|
|
738
|
+
value: undefined
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
}));
|
|
744
|
+
/**
|
|
745
|
+
* Retrieves the `Some` values from an `Iterable` of `Option`s.
|
|
746
|
+
*
|
|
747
|
+
* @example
|
|
748
|
+
* import { getSomes } from "effect/Iterable"
|
|
749
|
+
* import { some, none } from "effect/Option"
|
|
750
|
+
*
|
|
751
|
+
* assert.deepStrictEqual(
|
|
752
|
+
* Array.from(getSomes([some(1), none(), some(2)])),
|
|
753
|
+
* [1, 2]
|
|
754
|
+
* )
|
|
755
|
+
*
|
|
756
|
+
* @category filtering
|
|
757
|
+
* @since 2.0.0
|
|
758
|
+
*/
|
|
759
|
+
const getSomes = exports.getSomes = /*#__PURE__*/filterMap(_Function.identity);
|
|
760
|
+
/**
|
|
761
|
+
* Retrieves the `Left` values from an `Iterable` of `Either`s.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* import { getLefts } from "effect/Iterable"
|
|
765
|
+
* import { right, left } from "effect/Either"
|
|
766
|
+
*
|
|
767
|
+
* assert.deepStrictEqual(
|
|
768
|
+
* Array.from(getLefts([right(1), left("err"), right(2)])),
|
|
769
|
+
* ["err"]
|
|
770
|
+
* )
|
|
771
|
+
*
|
|
772
|
+
* @category filtering
|
|
773
|
+
* @since 2.0.0
|
|
774
|
+
*/
|
|
775
|
+
const getLefts = self => filterMap(self, E.getLeft);
|
|
776
|
+
/**
|
|
777
|
+
* Retrieves the `Right` values from an `Iterable` of `Either`s.
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* import { getRights } from "effect/Iterable"
|
|
781
|
+
* import { right, left } from "effect/Either"
|
|
782
|
+
*
|
|
783
|
+
* assert.deepStrictEqual(
|
|
784
|
+
* Array.from(getRights([right(1), left("err"), right(2)])),
|
|
785
|
+
* [1, 2]
|
|
786
|
+
* )
|
|
787
|
+
*
|
|
788
|
+
* @category filtering
|
|
789
|
+
* @since 2.0.0
|
|
790
|
+
*/
|
|
791
|
+
exports.getLefts = getLefts;
|
|
792
|
+
const getRights = self => filterMap(self, E.getRight);
|
|
793
|
+
/**
|
|
794
|
+
* @category filtering
|
|
795
|
+
* @since 2.0.0
|
|
796
|
+
*/
|
|
797
|
+
exports.getRights = getRights;
|
|
798
|
+
const filter = exports.filter = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => ({
|
|
799
|
+
[Symbol.iterator]() {
|
|
800
|
+
const iterator = self[Symbol.iterator]();
|
|
801
|
+
let i = 0;
|
|
802
|
+
return {
|
|
803
|
+
next() {
|
|
804
|
+
let result = iterator.next();
|
|
805
|
+
while (!result.done) {
|
|
806
|
+
if (predicate(result.value, i++)) {
|
|
807
|
+
return {
|
|
808
|
+
done: false,
|
|
809
|
+
value: result.value
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
result = iterator.next();
|
|
813
|
+
}
|
|
814
|
+
return {
|
|
815
|
+
done: true,
|
|
816
|
+
value: undefined
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
}));
|
|
822
|
+
/**
|
|
823
|
+
* @category sequencing
|
|
824
|
+
* @since 2.0.0
|
|
825
|
+
*/
|
|
826
|
+
const flatMapNullable = exports.flatMapNullable = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => filterMap(self, a => {
|
|
827
|
+
const b = f(a);
|
|
828
|
+
return b == null ? O.none() : O.some(b);
|
|
829
|
+
}));
|
|
830
|
+
/**
|
|
831
|
+
* Check if a predicate holds true for some `Iterable` element.
|
|
832
|
+
*
|
|
833
|
+
* @category elements
|
|
834
|
+
* @since 2.0.0
|
|
835
|
+
*/
|
|
836
|
+
const some = exports.some = /*#__PURE__*/(0, _Function.dual)(2, (self, predicate) => {
|
|
837
|
+
let i = 0;
|
|
838
|
+
for (const a of self) {
|
|
839
|
+
if (predicate(a, i++)) {
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return false;
|
|
844
|
+
});
|
|
845
|
+
/**
|
|
846
|
+
* @category constructors
|
|
847
|
+
* @since 2.0.0
|
|
848
|
+
*/
|
|
849
|
+
const unfold = (b, f) => ({
|
|
850
|
+
[Symbol.iterator]() {
|
|
851
|
+
let next = b;
|
|
852
|
+
return {
|
|
853
|
+
next() {
|
|
854
|
+
const o = f(next);
|
|
855
|
+
if (O.isNone(o)) {
|
|
856
|
+
return {
|
|
857
|
+
done: true,
|
|
858
|
+
value: undefined
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
const [a, b] = o.value;
|
|
862
|
+
next = b;
|
|
863
|
+
return {
|
|
864
|
+
done: false,
|
|
865
|
+
value: a
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
/**
|
|
872
|
+
* Iterate over the `Iterable` applying `f`.
|
|
873
|
+
*
|
|
874
|
+
* @since 2.0.0
|
|
875
|
+
*/
|
|
876
|
+
exports.unfold = unfold;
|
|
877
|
+
const forEach = exports.forEach = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
878
|
+
let i = 0;
|
|
879
|
+
for (const a of self) {
|
|
880
|
+
f(a, i++);
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
/**
|
|
884
|
+
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
885
|
+
*
|
|
886
|
+
* @since 2.0.0
|
|
887
|
+
*/
|
|
888
|
+
const dedupeAdjacentWith = exports.dedupeAdjacentWith = /*#__PURE__*/(0, _Function.dual)(2, (self, isEquivalent) => ({
|
|
889
|
+
[Symbol.iterator]() {
|
|
890
|
+
const iterator = self[Symbol.iterator]();
|
|
891
|
+
let first = true;
|
|
892
|
+
let last;
|
|
893
|
+
function next() {
|
|
894
|
+
const result = iterator.next();
|
|
895
|
+
if (result.done) {
|
|
896
|
+
return {
|
|
897
|
+
done: true,
|
|
898
|
+
value: undefined
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
if (first) {
|
|
902
|
+
first = false;
|
|
903
|
+
last = result.value;
|
|
904
|
+
return result;
|
|
905
|
+
}
|
|
906
|
+
const current = result.value;
|
|
907
|
+
if (isEquivalent(last, current)) {
|
|
908
|
+
return next();
|
|
909
|
+
}
|
|
910
|
+
last = current;
|
|
911
|
+
return result;
|
|
912
|
+
}
|
|
913
|
+
return {
|
|
914
|
+
next
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
}));
|
|
918
|
+
/**
|
|
919
|
+
* Deduplicates adjacent elements that are identical.
|
|
920
|
+
*
|
|
921
|
+
* @since 2.0.0
|
|
922
|
+
*/
|
|
923
|
+
const dedupeAdjacent = exports.dedupeAdjacent = /*#__PURE__*/dedupeAdjacentWith( /*#__PURE__*/Equal.equivalence());
|
|
924
|
+
/**
|
|
925
|
+
* Zips this Iterable crosswise with the specified Iterable using the specified combiner.
|
|
926
|
+
*
|
|
927
|
+
* @since 2.0.0
|
|
928
|
+
* @category elements
|
|
929
|
+
*/
|
|
930
|
+
const cartesianWith = exports.cartesianWith = /*#__PURE__*/(0, _Function.dual)(3, (self, that, f) => flatMap(self, a => map(that, b => f(a, b))));
|
|
931
|
+
/**
|
|
932
|
+
* Zips this Iterable crosswise with the specified Iterable.
|
|
933
|
+
*
|
|
934
|
+
* @since 2.0.0
|
|
935
|
+
* @category elements
|
|
936
|
+
*/
|
|
937
|
+
const cartesian = exports.cartesian = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => cartesianWith(self, that, (a, b) => [a, b]));
|
|
938
|
+
//# sourceMappingURL=Iterable.js.map
|