functionalscript 0.0.216 → 0.0.217
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/operator/README.md +30 -30
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Operator
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
`flatMap = combine(flat)(map)`
|
|
6
|
-
|
|
7
|
-
## A `Scan` Operator
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
type Scan<A, T> = (accumulator: A) => (value: T) => A
|
|
11
|
-
type ExclusiveScan<A, T> = [first, Scan<A, T>]
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
`scan`
|
|
15
|
-
|
|
16
|
-
`reduce = last(first)(scan)`
|
|
17
|
-
|
|
18
|
-
An alternative definition of a scan:
|
|
3
|
+
## Sequence
|
|
19
4
|
|
|
20
5
|
```ts
|
|
21
|
-
type
|
|
22
|
-
type ExclusiveScan2<A, T> = [first, Scan2<A, T>]
|
|
6
|
+
type Sequence<T> = SubSequence<T, undefined>
|
|
23
7
|
```
|
|
24
8
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## A Universal Operator `FlatScan`
|
|
9
|
+
## SubSequence
|
|
28
10
|
|
|
29
11
|
```ts
|
|
30
|
-
type
|
|
31
|
-
type
|
|
32
|
-
type FlatScanResult<A, T> =
|
|
33
|
-
['value', A, FlatScanSequence<A, T>] |
|
|
34
|
-
['novalue', FlatScan<A, T>]
|
|
12
|
+
type SubSequence<T, C> = () => SubSequenceResult<T, C>
|
|
13
|
+
type SubSequenceResult<T, C> = [T, SubSequence<T, C>] | [C]
|
|
35
14
|
```
|
|
36
15
|
|
|
37
|
-
|
|
16
|
+
## The Main FlatScan Operator
|
|
38
17
|
|
|
39
18
|
```ts
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
type FlatScanOperator<T, A> = (value: T) => SubSequence<A, FlatScanOp<T, A>>
|
|
20
|
+
|
|
21
|
+
const flatScanConcat
|
|
22
|
+
: SubSequence<A, FlatScanOp<T, A>> => Sequence<T> => Sequence<A>
|
|
23
|
+
=> a => b => () => {
|
|
24
|
+
switch (next(a)) {
|
|
25
|
+
case [first, tail]: { return [first, flatScanConcat(tail)(b)] }
|
|
26
|
+
case [operator]: { return flatScan(operator)(b)() }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const flatScan
|
|
31
|
+
: FlatScanOperator<T, A> => Sequence<T> => Sequence<A>
|
|
32
|
+
=> operator => sequence => () => {
|
|
33
|
+
// optimization for `takeWhile`, `find`
|
|
34
|
+
if (operator === flatScanEmpty) { return [undefined] }
|
|
35
|
+
//
|
|
36
|
+
switch (next(s)) {
|
|
37
|
+
case [first, tail]: { return flatScanConcat(operator(first))(tail)() }
|
|
38
|
+
case [undefined]: { return [undefined] }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|