functionalscript 0.0.230 → 0.0.231
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/package.json +1 -1
- package/sequence/index.js +15 -15
package/package.json
CHANGED
package/sequence/index.js
CHANGED
|
@@ -61,14 +61,14 @@ const next = sequence => {
|
|
|
61
61
|
const n = node(i)
|
|
62
62
|
if (!(n instanceof Array)) { return n }
|
|
63
63
|
const [a, b] = n
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
64
|
+
const aNode = node(a)
|
|
65
|
+
if (aNode === undefined) {
|
|
66
66
|
i = b
|
|
67
|
-
} else if (
|
|
68
|
-
const [aa, ab] =
|
|
67
|
+
} else if (aNode instanceof Array) {
|
|
68
|
+
const [aa, ab] = aNode
|
|
69
69
|
i = () => [aa, () => [ab, b]]
|
|
70
70
|
} else {
|
|
71
|
-
const { first, tail } =
|
|
71
|
+
const { first, tail } = aNode
|
|
72
72
|
return { first, tail: () => [tail, b] }
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -198,24 +198,24 @@ const countdown = count => () => {
|
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
200
|
* @template T,A
|
|
201
|
-
* @typedef {(value: T) => ScanState<T, A>}
|
|
201
|
+
* @typedef {(value: T) => ScanState<T, A>} ScanOperator
|
|
202
202
|
*/
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* @template T,A
|
|
206
|
-
* @typedef {readonly[A,
|
|
206
|
+
* @typedef {readonly[A, ScanOperator<T, A>]} ScanState
|
|
207
207
|
*/
|
|
208
208
|
|
|
209
|
-
/** @type {<T,A>(operator:
|
|
209
|
+
/** @type {<T,A>(operator: ScanOperator<T, A>) => (result: ResultOne<T>) => Node<A>} */
|
|
210
210
|
const scanFn = operator => ({first, tail}) => {
|
|
211
211
|
const [value, nextOperator] = operator(first)
|
|
212
212
|
return { first: value, tail: scan(nextOperator)(tail) }
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
/** @type {<T,A>(operator:
|
|
215
|
+
/** @type {<T,A>(operator: ScanOperator<T, A>) => (input: Sequence<T>) => Thunk<A>} */
|
|
216
216
|
const scan = operator => nextMap(scanFn(operator))
|
|
217
217
|
|
|
218
|
-
/** @type {<T,A>(operator:
|
|
218
|
+
/** @type {<T,A>(operator: ScanOperator<T, A>) => <D>(def: D)=> (input: Sequence<T>) => D|A} */
|
|
219
219
|
const scanReduce = operator => def => input => last(def)(scan(operator)(input))
|
|
220
220
|
|
|
221
221
|
/**
|
|
@@ -224,16 +224,16 @@ const scanReduce = operator => def => input => last(def)(scan(operator)(input))
|
|
|
224
224
|
*/
|
|
225
225
|
|
|
226
226
|
/** @type {<T,A>(operator: ReduceOperator<T, A>) => (init: A) => ScanState<T, A>} */
|
|
227
|
-
const scanState = operator => init => [init,
|
|
227
|
+
const scanState = operator => init => [init, scanOperator(operator)(init)]
|
|
228
228
|
|
|
229
|
-
/** @type {<T,A>(operator: ReduceOperator<T, A>) => (init: A) =>
|
|
230
|
-
const
|
|
229
|
+
/** @type {<T,A>(operator: ReduceOperator<T, A>) => (init: A) => ScanOperator<T, A>} */
|
|
230
|
+
const scanOperator = operator => init => value => {
|
|
231
231
|
const result = operator(init)(value)
|
|
232
232
|
return scanState(operator)(result)
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/** @type {<T,A>(operator: ReduceOperator<T, A>) => (init: A) => (input: Sequence<T>) => A} */
|
|
236
|
-
const reduce = operator => init => scanReduce(
|
|
236
|
+
const reduce = operator => init => scanReduce(scanOperator(operator)(init))(init)
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
239
|
* @template T
|
|
@@ -311,7 +311,7 @@ module.exports = {
|
|
|
311
311
|
/** @readonly */
|
|
312
312
|
dropWhile,
|
|
313
313
|
/** @readonly */
|
|
314
|
-
scanFunc,
|
|
314
|
+
scanFunc: scanOperator,
|
|
315
315
|
/** @readonly */
|
|
316
316
|
scanState,
|
|
317
317
|
/** @readonly */
|