functionalscript 0.0.157 → 0.0.161
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/array/index.js +55 -1
- package/async/index.js +1 -1
- package/btree/index.js +34 -23
- package/dev/index.js +4 -0
- package/func/index.js +12 -0
- package/index.js +0 -2
- package/iterable/index.js +1 -2
- package/iterable/test.js +2 -2
- package/map/index.js +3 -3
- package/map/test.js +0 -1
- package/map-reduce/index.js +2 -2
- package/module-manager/index.js +40 -28
- package/module-manager/node/test.js +0 -1
- package/module-manager/test.js +0 -2
- package/option/index.js +12 -0
- package/package.json +1 -1
- package/test.js +0 -2
- package/lib/index.js +0 -97
- package/lib/test.js +0 -5
package/array/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
const option = require('../option')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @template T
|
|
5
|
+
* @typedef {readonly T[]} Array
|
|
6
|
+
*/
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* @template T
|
|
3
10
|
* @typedef {readonly [T]} Array1
|
|
@@ -33,4 +40,51 @@
|
|
|
33
40
|
|
|
34
41
|
/** @typedef {0|1|2|3|4} Index5 */
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
/** @type {<T>(_: Array<T>) => Array<T>} */
|
|
44
|
+
const uncheckTail = a => a.slice(1)
|
|
45
|
+
|
|
46
|
+
/** @type {<T>(_: Array<T>) => Array<T>} */
|
|
47
|
+
const uncheckHead = a => a.slice(0, -1)
|
|
48
|
+
|
|
49
|
+
/** @type {<T>(_: Array<T>) => T|undefined} */
|
|
50
|
+
const first = a => a[0]
|
|
51
|
+
|
|
52
|
+
/** @type {<T>(_: Array<T>) => T|undefined} */
|
|
53
|
+
const last = a => a[a.length - 1]
|
|
54
|
+
|
|
55
|
+
/** @type {<T>(_: Array<T>) => Array<T>|undefined} */
|
|
56
|
+
const tail = a => a.length === 0 ? undefined : uncheckTail(a)
|
|
57
|
+
|
|
58
|
+
/** @type {<T>(_: Array<T>) => readonly [T, Array<T>]|undefined} */
|
|
59
|
+
const splitFirst = a => {
|
|
60
|
+
/** @typedef {typeof a[0]} T*/
|
|
61
|
+
/** @type {(_: T) => readonly [T, Array<T>]} */
|
|
62
|
+
const split = first => [first, uncheckTail(a)]
|
|
63
|
+
return option.map(split)(a[0])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @type {<T>(_: Array<T>) => Array<T>|undefined} */
|
|
67
|
+
const head = a => a.length === 0 ? undefined : uncheckHead(a)
|
|
68
|
+
|
|
69
|
+
/** @type {<T>(_: Array<T>) => readonly [Array<T>, T]|undefined} */
|
|
70
|
+
const splitLast = a => {
|
|
71
|
+
/** @typedef {typeof a[0]} T*/
|
|
72
|
+
/** @type {(_: T) => readonly [Array<T>, T]} */
|
|
73
|
+
const split = x => [uncheckHead(a), x]
|
|
74
|
+
return option.map(split)(last(a))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = {
|
|
78
|
+
/** @readnly */
|
|
79
|
+
first,
|
|
80
|
+
/** @readonly */
|
|
81
|
+
last,
|
|
82
|
+
/** @readonly */
|
|
83
|
+
head,
|
|
84
|
+
/** @readonly */
|
|
85
|
+
tail,
|
|
86
|
+
/** @readonly */
|
|
87
|
+
splitFirst,
|
|
88
|
+
/** @readonly */
|
|
89
|
+
splitLast,
|
|
90
|
+
}
|
package/async/index.js
CHANGED
package/btree/index.js
CHANGED
|
@@ -55,27 +55,37 @@ const { index3, index5 } = require('../cmp')
|
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @template T
|
|
58
|
-
* @typedef {Leaf1<T
|
|
58
|
+
* @typedef { Leaf1<T> | Leaf2<T> | Branch3<T> | Branch5<T>} TNode
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/** @typedef {{ readonly done: false }} NotFoundDone */
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @template T
|
|
65
|
+
* @typedef {{
|
|
66
|
+
* readonly done: true
|
|
67
|
+
* readonly value: T
|
|
68
|
+
* }} FoundDone
|
|
59
69
|
*/
|
|
60
70
|
|
|
61
71
|
/**
|
|
62
72
|
* @template T
|
|
63
|
-
* @typedef {
|
|
73
|
+
* @typedef { NotFoundDone | FoundDone<T> } Done
|
|
64
74
|
*/
|
|
65
75
|
|
|
66
76
|
/**
|
|
67
77
|
* @template T
|
|
68
|
-
* @typedef {{ replace: TNode<T> }} Replace
|
|
78
|
+
* @typedef {{ readonly replace: TNode<T> }} Replace
|
|
69
79
|
*/
|
|
70
80
|
|
|
71
81
|
/**
|
|
72
82
|
* @template T
|
|
73
|
-
* @typedef {{ overflow: Branch3<T> }} Overflow
|
|
83
|
+
* @typedef {{ readonly overflow: Branch3<T> }} Overflow
|
|
74
84
|
*/
|
|
75
85
|
|
|
76
86
|
/**
|
|
77
87
|
* @template T
|
|
78
|
-
* @typedef {Done<T> | Replace<T> | Overflow<T>} Result
|
|
88
|
+
* @typedef { Done<T> | Replace<T> | Overflow<T> } Result
|
|
79
89
|
*/
|
|
80
90
|
|
|
81
91
|
/** @typedef {<T>(_: Lazy<T>) => (_: Leaf1<T>) => Result<T>} InLeaf1 */
|
|
@@ -85,35 +95,35 @@ const { index3, index5 } = require('../cmp')
|
|
|
85
95
|
|
|
86
96
|
/**
|
|
87
97
|
* @typedef {{
|
|
88
|
-
* leaf1: InLeaf1
|
|
89
|
-
* leaf2_left: InLeaf2
|
|
90
|
-
* leaf2_right: InLeaf2
|
|
91
|
-
* branch3: InBranch3
|
|
92
|
-
* branch5_left: InBranch5
|
|
93
|
-
* branch5_right: InBranch5
|
|
98
|
+
* readonly leaf1: InLeaf1
|
|
99
|
+
* readonly leaf2_left: InLeaf2
|
|
100
|
+
* readonly leaf2_right: InLeaf2
|
|
101
|
+
* readonly branch3: InBranch3
|
|
102
|
+
* readonly branch5_left: InBranch5
|
|
103
|
+
* readonly branch5_right: InBranch5
|
|
94
104
|
* }} Found
|
|
95
105
|
*/
|
|
96
106
|
|
|
97
107
|
/**
|
|
98
108
|
* @typedef {{
|
|
99
|
-
* leaf1_left: InLeaf1
|
|
100
|
-
* leaf1_right: InLeaf1
|
|
101
|
-
* leaf2_left: InLeaf2
|
|
102
|
-
* leaf2_middle: InLeaf2
|
|
103
|
-
* leaf2_right: InLeaf2
|
|
109
|
+
* readonly leaf1_left: InLeaf1
|
|
110
|
+
* readonly leaf1_right: InLeaf1
|
|
111
|
+
* readonly leaf2_left: InLeaf2
|
|
112
|
+
* readonly leaf2_middle: InLeaf2
|
|
113
|
+
* readonly leaf2_right: InLeaf2
|
|
104
114
|
* }} NotFound
|
|
105
115
|
*/
|
|
106
116
|
|
|
107
117
|
/**
|
|
108
118
|
* @typedef {{
|
|
109
|
-
* found: Found
|
|
110
|
-
* notFound: NotFound
|
|
119
|
+
* readonly found: Found
|
|
120
|
+
* readonly notFound: NotFound
|
|
111
121
|
* }} Visitor
|
|
112
122
|
*/
|
|
113
123
|
|
|
114
124
|
/**
|
|
115
125
|
* @template T
|
|
116
|
-
* @typedef {readonly [TNode<T>, T, TNode<T>, T, TNode<T>, T, TNode<T>]} Branch7
|
|
126
|
+
* @typedef { readonly [TNode<T>, T, TNode<T>, T, TNode<T>, T, TNode<T>] } Branch7
|
|
117
127
|
*/
|
|
118
128
|
|
|
119
129
|
/** @type {<T>(n: Branch7<T>) => Branch3<T>} */
|
|
@@ -221,7 +231,7 @@ const visit = ({ found, notFound }) => cmp => {
|
|
|
221
231
|
}
|
|
222
232
|
}
|
|
223
233
|
|
|
224
|
-
/** @type {<T>(_: T) => Done<T>} */
|
|
234
|
+
/** @type { <T>(_: T) => Done<T> } */
|
|
225
235
|
const found = value => ({ done: true, value })
|
|
226
236
|
|
|
227
237
|
/** @type {Found} */
|
|
@@ -233,7 +243,7 @@ const foundGet = {
|
|
|
233
243
|
branch5_left: () => ([, value]) => found(value),
|
|
234
244
|
branch5_right: () => ([, , , value]) => found(value),
|
|
235
245
|
}
|
|
236
|
-
/** @type {() => () =>
|
|
246
|
+
/** @type { () => () => NotFoundDone } */
|
|
237
247
|
const notFound = () => () => ({ done: false })
|
|
238
248
|
|
|
239
249
|
/** @type {NotFound} */
|
|
@@ -245,7 +255,7 @@ const notFoundGet = {
|
|
|
245
255
|
leaf2_right: notFound,
|
|
246
256
|
}
|
|
247
257
|
|
|
248
|
-
/** @type {<T>(_: TNode<T>) => Replace<T>} */
|
|
258
|
+
/** @type { <T>(_: TNode<T>) => Replace<T> } */
|
|
249
259
|
const replace = node => ({ replace: node })
|
|
250
260
|
|
|
251
261
|
/** @type {Found} */
|
|
@@ -288,6 +298,7 @@ const getOrInsertVisitor = {
|
|
|
288
298
|
notFound: notFoundInsert,
|
|
289
299
|
}
|
|
290
300
|
|
|
301
|
+
/** @type {Visitor} */
|
|
291
302
|
const replaceVisitor = {
|
|
292
303
|
found: foundReplace,
|
|
293
304
|
notFound: notFoundGet,
|
|
@@ -324,7 +335,7 @@ module.exports = {
|
|
|
324
335
|
values,
|
|
325
336
|
/**
|
|
326
337
|
* @readonly
|
|
327
|
-
* @type {<T>(cmp: Cmp<T>) => (node: TNode<T>) => T|undefined}
|
|
338
|
+
* @type { <T>(cmp: Cmp<T>) => (node: TNode<T>) => T|undefined }
|
|
328
339
|
*/
|
|
329
340
|
getVisitor: cmp => node => {
|
|
330
341
|
const result = visit(getVisitor)(cmp)(() => { throw '' })(node)
|
package/dev/index.js
ADDED
package/func/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @type {<I, X>(_: (_: I) => X) => <O>(_: (_: X) => O) => (_: I) => O} */
|
|
2
|
+
const pipe = g => f => x => f(g(x))
|
|
3
|
+
|
|
4
|
+
/** @type {<T>(value: T) => T} */
|
|
5
|
+
const id = value => value
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
/** @readonly */
|
|
9
|
+
id,
|
|
10
|
+
/** @readonly */
|
|
11
|
+
pipe,
|
|
12
|
+
}
|
package/index.js
CHANGED
package/iterable/index.js
CHANGED
package/iterable/test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const i = require('.')
|
|
2
|
-
const
|
|
2
|
+
const { pipe } = require('../func')
|
|
3
3
|
|
|
4
4
|
{
|
|
5
5
|
const r = i.sum([120, 300, 42])
|
|
@@ -33,7 +33,7 @@ const lib = require('../lib')
|
|
|
33
33
|
/** @type {(_: string) => string|undefined} */
|
|
34
34
|
const file = _ => 'x'
|
|
35
35
|
/** @type {(_: string) => string|undefined} */
|
|
36
|
-
const x = p =>
|
|
36
|
+
const x = p => pipe
|
|
37
37
|
(i.map(x => file(x())))
|
|
38
38
|
(i.find(x => x !== undefined))
|
|
39
39
|
([() => p, () => `${p}.js`, () => `${p}/index.js`])
|
package/map/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const option = require("../option")
|
|
2
2
|
const { getVisitor, setVisitor, values } = require("../btree")
|
|
3
3
|
|
|
4
4
|
/** @typedef {import("../cmp").Sign} Sign */
|
|
@@ -38,7 +38,7 @@ const cmp = a => ([b]) => a < b ? -1 : a === b ? 0 : 1
|
|
|
38
38
|
|
|
39
39
|
/** @type {<T>(node: TNode<Entry<T>>) => Map<T>} */
|
|
40
40
|
const create = root => ({
|
|
41
|
-
get: name =>
|
|
41
|
+
get: name => option.map(([,value]) => value)(getVisitor(cmp(name))(root)),
|
|
42
42
|
set: name => value => {
|
|
43
43
|
const result = setVisitor(cmp(name))(() => [name, value])(root)
|
|
44
44
|
if ('replace' in result) { return create(result.replace) }
|
|
@@ -53,7 +53,7 @@ const create = root => ({
|
|
|
53
53
|
* @type {{
|
|
54
54
|
* readonly get: (name: string) => undefined
|
|
55
55
|
* readonly set: (name: string) => <T>(value: T) => Map<T>
|
|
56
|
-
* readonly entries: () => []
|
|
56
|
+
* readonly entries: () => readonly []
|
|
57
57
|
* readonly root: undefined
|
|
58
58
|
* }}
|
|
59
59
|
*/
|
package/map/test.js
CHANGED
package/map-reduce/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { pipe } = require('../
|
|
1
|
+
const { pipe, id } = require('../func')
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @template I
|
|
@@ -28,7 +28,7 @@ const join = separator => ({
|
|
|
28
28
|
/** @type {Operation<number, number, number>} */
|
|
29
29
|
const sum = {
|
|
30
30
|
reduce: a => i => a + i,
|
|
31
|
-
result:
|
|
31
|
+
result: id,
|
|
32
32
|
init: 0,
|
|
33
33
|
}
|
|
34
34
|
|
package/module-manager/index.js
CHANGED
|
@@ -1,35 +1,45 @@
|
|
|
1
|
-
const
|
|
1
|
+
const array = require('../array')
|
|
2
|
+
const { pipe } = require('../func')
|
|
3
|
+
const option = require('../option')
|
|
4
|
+
const { head, last, splitLast, splitFirst } = array
|
|
2
5
|
const iter = require('../iterable')
|
|
3
6
|
const mr = require('../map-reduce')
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @template T
|
|
10
|
+
* @typedef {array.Array<T>} Array
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @typedef {Array<string>} Path */
|
|
14
|
+
|
|
5
15
|
/** @typedef {(_: string) => string|undefined} ReadFile */
|
|
6
16
|
|
|
7
17
|
/**
|
|
8
18
|
* @typedef {{
|
|
9
|
-
* id: string
|
|
10
|
-
* dependencies: Dependencies
|
|
11
|
-
* file: ReadFile
|
|
19
|
+
* readonly id: Array<string>
|
|
20
|
+
* readonly dependencies: Dependencies
|
|
21
|
+
* readonly file: ReadFile
|
|
12
22
|
* }} Package
|
|
13
23
|
*/
|
|
14
24
|
|
|
15
25
|
/**
|
|
16
26
|
* @typedef {{
|
|
17
|
-
* pack: Package,
|
|
18
|
-
* local: string
|
|
27
|
+
* readonly pack: Package,
|
|
28
|
+
* readonly local: Array<string>,
|
|
19
29
|
* }} Location
|
|
20
30
|
*/
|
|
21
31
|
|
|
22
32
|
/**
|
|
23
33
|
* @typedef {{
|
|
24
|
-
* fileName: string
|
|
25
|
-
* location: Location
|
|
26
|
-
* source: string
|
|
34
|
+
* readonly fileName: string
|
|
35
|
+
* readonly location: Location
|
|
36
|
+
* readonly source: string
|
|
27
37
|
* }} Module
|
|
28
38
|
*/
|
|
29
39
|
|
|
30
40
|
/** @typedef {(_: string) => undefined|Package|Dependencies} Dependencies */
|
|
31
41
|
|
|
32
|
-
/** @type {mr.Operation<string, undefined|
|
|
42
|
+
/** @type {mr.Operation<string, undefined|Path, undefined|Path>} */
|
|
33
43
|
const pathNormReduce = {
|
|
34
44
|
reduce: path => item =>
|
|
35
45
|
path === undefined ?
|
|
@@ -37,50 +47,52 @@ const pathNormReduce = {
|
|
|
37
47
|
['', '.'].includes(item) ?
|
|
38
48
|
path :
|
|
39
49
|
item === '..' ?
|
|
40
|
-
|
|
50
|
+
head(path) :
|
|
41
51
|
[...path, item],
|
|
42
52
|
init: [],
|
|
43
53
|
result: s => s,
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
/** @type {(_: string
|
|
56
|
+
/** @type {(_: Array<string>) => boolean} */
|
|
47
57
|
const isRelative = localId => ['.', '..'].includes(localId[0])
|
|
48
58
|
|
|
49
59
|
const pathNorm = iter.apply(pathNormReduce)
|
|
50
60
|
|
|
51
|
-
/** @type {(_: Package) => (_:
|
|
61
|
+
/** @type {(_: Package) => (_: Path) => Module|undefined} */
|
|
52
62
|
const internal = pack => {
|
|
53
|
-
/** @type {(_:
|
|
63
|
+
/** @type {(_: Path) => (_: string) => Module|undefined} */
|
|
54
64
|
const readFile = local => fileName => {
|
|
55
65
|
const source = pack.file([...local, fileName].join('/'))
|
|
56
66
|
return source === undefined ? undefined : { fileName, location: { pack, local }, source}
|
|
57
67
|
}
|
|
58
68
|
return path => {
|
|
59
|
-
/** @type {(_:
|
|
69
|
+
/** @type {(_: Path) => Module|undefined} */
|
|
60
70
|
const read = local => {
|
|
61
|
-
/** @type {(_: [
|
|
62
|
-
const tryFiles = ([head,
|
|
71
|
+
/** @type {(_: readonly[Path, string]) => Module|undefined} */
|
|
72
|
+
const tryFiles = ([head, file]) => {
|
|
63
73
|
/** @type {(_: string) => Module|undefined} */
|
|
64
|
-
const one = ext => readFile(head)(
|
|
65
|
-
return ['.', '..', '', undefined].includes(
|
|
74
|
+
const one = ext => readFile(head)(file + ext)
|
|
75
|
+
return ['.', '..', '', undefined].includes(last(path)) ? undefined : one('') ?? one('.js')
|
|
66
76
|
}
|
|
67
|
-
return
|
|
77
|
+
return option.map(tryFiles)(splitLast(local)) ?? readFile(local)('index.js')
|
|
68
78
|
}
|
|
69
|
-
return
|
|
79
|
+
return option.map(read)(pathNorm(path))
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
|
|
73
|
-
/** @type {(_: Package|Dependencies|undefined) => (_:
|
|
83
|
+
/** @type {(_: Package|Dependencies|undefined) => (_: Path) => Module|undefined} */
|
|
74
84
|
const externalOrInternal = p =>
|
|
75
85
|
p === undefined ? () => undefined : (typeof p === 'function' ? external(p) : internal(p))
|
|
76
86
|
|
|
77
|
-
/** @type {(_: Dependencies) => (_:
|
|
87
|
+
/** @type {(_: Dependencies) => (_: Path) => Module|undefined} */
|
|
78
88
|
const external = packages => {
|
|
79
|
-
/** @type {(_: [string,
|
|
89
|
+
/** @type {(_: readonly [string, Path]) => Module|undefined} */
|
|
80
90
|
const defined = ([first, tail]) => externalOrInternal(packages(first))(tail)
|
|
81
|
-
/** @type {(_:
|
|
82
|
-
const
|
|
83
|
-
return
|
|
91
|
+
/** @type {(_: Path) => readonly [string, Path]|undefined} */
|
|
92
|
+
const sf = splitFirst
|
|
93
|
+
return pipe
|
|
94
|
+
(sf)
|
|
95
|
+
(option.map(defined))
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
/** @type {(_: Location) => (_: string) => Module|undefined} */
|
|
@@ -101,4 +113,4 @@ module.exports = {
|
|
|
101
113
|
getModule,
|
|
102
114
|
/** @readonly */
|
|
103
115
|
moduleId,
|
|
104
|
-
}
|
|
116
|
+
}
|
package/module-manager/test.js
CHANGED
package/option/index.js
ADDED
package/package.json
CHANGED
package/test.js
CHANGED
package/lib/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @template T
|
|
5
|
-
* @typedef {T|undefined} Option
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @template T
|
|
10
|
-
* @typedef {() => NotEmptySequence<T>|undefined} Sequence
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @template T
|
|
15
|
-
* @typedef {{ first: T, tail: Sequence<T>}} NotEmptySequence
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @template T
|
|
20
|
-
* @typedef {() => Continuation<T>} Continue
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @template T
|
|
25
|
-
* @typedef {[T]|Continue<T>} Continuation
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/** @type {<I, X>(_: (_: I) => X) => <O>(_: (_: X) => O) => (_: I) => O} */
|
|
29
|
-
const pipe = g => f => x => f(g(x))
|
|
30
|
-
|
|
31
|
-
/** @type {<T, R>(_: (_: T) => R) => (_: T|undefined) => R|undefined} */
|
|
32
|
-
const optionMap = f => x => x === undefined ? undefined : f(x)
|
|
33
|
-
|
|
34
|
-
/** @type {<T>(_: T[]) => T[]} */
|
|
35
|
-
const uncheckTail = a => a.slice(1)
|
|
36
|
-
|
|
37
|
-
/** @type {<T>(_: T[]) => T[]} */
|
|
38
|
-
const uncheckHead = a => a.slice(0, -1)
|
|
39
|
-
|
|
40
|
-
/** @type {<T>(_: T[]) => T|undefined} */
|
|
41
|
-
const last = a => a[a.length - 1]
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @template I
|
|
45
|
-
* @typedef {{
|
|
46
|
-
* readonly i: <O>(f: (input: I) => O) => Chain<O>
|
|
47
|
-
* readonly result: () => I
|
|
48
|
-
* }} Chain
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
/** @type {<I>(value: I) => Chain<I>} */
|
|
52
|
-
const chain = value => ({
|
|
53
|
-
i: f => chain(f(value)),
|
|
54
|
-
result: () => value
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @template I
|
|
59
|
-
* @template T
|
|
60
|
-
* @typedef {{
|
|
61
|
-
* readonly x: <O>(f: (v: T) => O) => Pipe<I, O>
|
|
62
|
-
* readonly f: (input: I) => T
|
|
63
|
-
* }} Pipe
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
module.exports = {
|
|
67
|
-
|
|
68
|
-
todo: () => { throw 'not implemented' },
|
|
69
|
-
|
|
70
|
-
pipe,
|
|
71
|
-
|
|
72
|
-
last,
|
|
73
|
-
|
|
74
|
-
optionMap,
|
|
75
|
-
|
|
76
|
-
/** @type {<T>(_: T[]) => T[]|undefined} */
|
|
77
|
-
tail: a => a.length === 0 ? undefined : uncheckTail(a),
|
|
78
|
-
|
|
79
|
-
/** @type {<T>(_: T[]) => [T, T[]]|undefined} */
|
|
80
|
-
splitFirst: a => {
|
|
81
|
-
/** @typedef {typeof a[0]} T*/
|
|
82
|
-
/** @type {(_: T) => [T, T[]]} */
|
|
83
|
-
const split = first => [first, uncheckTail(a)]
|
|
84
|
-
return optionMap(split)(a[0])
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
/** @type {<T>(_: T[]) => T[]|undefined} */
|
|
88
|
-
head: a => a.length === 0 ? undefined : uncheckHead(a),
|
|
89
|
-
|
|
90
|
-
/** @type {<T>(_: T[]) => [T[], T]|undefined} */
|
|
91
|
-
splitLast: a => {
|
|
92
|
-
/** @typedef {typeof a[0]} T*/
|
|
93
|
-
/** @type {(_: T) => [T[], T]} */
|
|
94
|
-
const split = x => [uncheckHead(a), x]
|
|
95
|
-
return optionMap(split)(last(a))
|
|
96
|
-
},
|
|
97
|
-
}
|