functionalscript 0.0.483 → 0.0.485
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/text/ascii/module.f.cjs +1 -1
- package/text/utf16/module.f.cjs +14 -14
- package/types/array/module.f.cjs +17 -14
- package/types/array/test.f.cjs +10 -14
package/package.json
CHANGED
package/text/ascii/module.f.cjs
CHANGED
package/text/utf16/module.f.cjs
CHANGED
|
@@ -2,11 +2,11 @@ const list = require('../../types/list/module.f.cjs')
|
|
|
2
2
|
const operator = require('../../types/function/operator/module.f.cjs')
|
|
3
3
|
const { contains } = require('../../types/range/module.f.cjs')
|
|
4
4
|
const { fn } = require('../../types/function/module.f.cjs')
|
|
5
|
-
const { map, flat, stateScan, reduce, flatMap } = list
|
|
5
|
+
const { map, flat, stateScan, reduce, flatMap, empty } = list
|
|
6
6
|
|
|
7
|
-
/** @typedef {u16|
|
|
7
|
+
/** @typedef {u16|null} WordOrEof */
|
|
8
8
|
|
|
9
|
-
/** @typedef {
|
|
9
|
+
/** @typedef {number|null} Utf16State */
|
|
10
10
|
|
|
11
11
|
/** @typedef {number} u16 */
|
|
12
12
|
|
|
@@ -50,39 +50,39 @@ const utf16ByteToCodePointOp = state => word => {
|
|
|
50
50
|
if (!u16(word)) {
|
|
51
51
|
return [[0xffffffff], state]
|
|
52
52
|
}
|
|
53
|
-
if (state ===
|
|
54
|
-
if (isBmpCodePoint(word)) { return [[word],
|
|
53
|
+
if (state === null) {
|
|
54
|
+
if (isBmpCodePoint(word)) { return [[word], null] }
|
|
55
55
|
if (isHighSurrogate(word)) { return [[], word] }
|
|
56
|
-
return [[word | errorMask],
|
|
56
|
+
return [[word | errorMask], null]
|
|
57
57
|
}
|
|
58
58
|
if (isLowSurrogate(word)) {
|
|
59
59
|
const high = state - 0xd800
|
|
60
60
|
const low = word - 0xdc00
|
|
61
|
-
return [[(high << 10) + low + 0x10000],
|
|
61
|
+
return [[(high << 10) + low + 0x10000], null]
|
|
62
62
|
}
|
|
63
|
-
if (isBmpCodePoint(word)) { return [[state | errorMask, word],
|
|
63
|
+
if (isBmpCodePoint(word)) { return [[state | errorMask, word], null] }
|
|
64
64
|
if (isHighSurrogate(word)) { return [[state | errorMask], word] }
|
|
65
|
-
return [[state | errorMask, word | errorMask],
|
|
65
|
+
return [[state | errorMask, word | errorMask], null]
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/** @type {(state: Utf16State) => readonly[list.List<i32>, Utf16State]} */
|
|
69
|
-
const utf16EofToCodePointOp = state => [state ===
|
|
69
|
+
const utf16EofToCodePointOp = state => [state === null ? empty : [state | errorMask], null]
|
|
70
70
|
|
|
71
71
|
/** @type {operator.StateScan<WordOrEof, Utf16State, list.List<i32>>} */
|
|
72
|
-
const utf16ByteOrEofToCodePointOp = state => input => input ===
|
|
72
|
+
const utf16ByteOrEofToCodePointOp = state => input => input === null ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input)
|
|
73
73
|
|
|
74
74
|
/** @type {list.List<WordOrEof>} */
|
|
75
|
-
const eofList = [
|
|
75
|
+
const eofList = [null]
|
|
76
76
|
|
|
77
77
|
/** @type {(input: list.List<u16>) => list.List<i32>} */
|
|
78
|
-
const toCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(
|
|
78
|
+
const toCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(null)(flat([input, eofList])))
|
|
79
79
|
|
|
80
80
|
/** @type {(s: string) => list.List<u16>} */
|
|
81
81
|
const stringToList = s => {
|
|
82
82
|
/** @type {(i: number) => list.Result<number>} */
|
|
83
83
|
const at = i => {
|
|
84
84
|
const first = s.charCodeAt(i)
|
|
85
|
-
return isNaN(first) ?
|
|
85
|
+
return isNaN(first) ? empty : { first, tail: () => at(i + 1) }
|
|
86
86
|
}
|
|
87
87
|
return at(0)
|
|
88
88
|
}
|
package/types/array/module.f.cjs
CHANGED
|
@@ -84,35 +84,38 @@ const uncheckTail = a => a.slice(1)
|
|
|
84
84
|
/** @type {<T>(_: readonly T[]) => readonly T[]} */
|
|
85
85
|
const uncheckHead = a => a.slice(0, -1)
|
|
86
86
|
|
|
87
|
-
/** @type {<T>(
|
|
88
|
-
const
|
|
87
|
+
/** @type {<T>(a: T|undefined) => T|null} */
|
|
88
|
+
const undefinedToNull = a => a === undefined ? null : a
|
|
89
89
|
|
|
90
|
-
/** @type {<T>(_: readonly T[]) => T|
|
|
91
|
-
const
|
|
90
|
+
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
91
|
+
const first = a => undefinedToNull(a[0])
|
|
92
92
|
|
|
93
|
-
/** @type {<T>(_: readonly T[]) =>
|
|
94
|
-
const
|
|
93
|
+
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
94
|
+
const last = a => undefinedToNull(a[a.length - 1])
|
|
95
95
|
|
|
96
|
-
/** @type {<T>(_: readonly T[]) => readonly
|
|
96
|
+
/** @type {<T>(_: readonly T[]) => readonly T[] | null} */
|
|
97
|
+
const tail = a => a.length === 0 ? null : uncheckTail(a)
|
|
98
|
+
|
|
99
|
+
/** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|null} */
|
|
97
100
|
const splitFirst = a => {
|
|
98
101
|
/** @typedef {typeof a[0]} T*/
|
|
99
102
|
/** @type {(_: T) => readonly[T, readonly T[]]} */
|
|
100
103
|
const split = first => [first, uncheckTail(a)]
|
|
101
|
-
return map(split)(a[0])
|
|
104
|
+
return undefinedToNull(map(split)(a[0]))
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
/** @type {<T>(_: readonly T[]) => readonly T[]|
|
|
105
|
-
const head = a => a.length === 0 ?
|
|
107
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]|null} */
|
|
108
|
+
const head = a => a.length === 0 ? null : uncheckHead(a)
|
|
106
109
|
|
|
107
|
-
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|
|
|
110
|
+
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|null} */
|
|
108
111
|
const splitLast = a => {
|
|
109
112
|
const lastA = last(a)
|
|
110
|
-
if (lastA ===
|
|
113
|
+
if (lastA === null) { return null }
|
|
111
114
|
return [uncheckHead(a), lastA]
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
/** @type {(index: number) => <T>(a: readonly T[]) => readonly[T]|
|
|
115
|
-
const at = index => a => index < a.length ? [a[index]] :
|
|
117
|
+
/** @type {(index: number) => <T>(a: readonly T[]) => readonly[T]|null} */
|
|
118
|
+
const at = index => a => index < a.length ? [a[index]] : null
|
|
116
119
|
|
|
117
120
|
module.exports = {
|
|
118
121
|
/** @readonly */
|
package/types/array/test.f.cjs
CHANGED
|
@@ -2,8 +2,7 @@ const _ = require('./module.f.cjs')
|
|
|
2
2
|
const json = require('../../json/module.f.cjs')
|
|
3
3
|
const { sort } = require('../object/module.f.cjs')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const stringify = a => json.stringify(sort)(a)
|
|
5
|
+
const stringify = json.stringify(sort)
|
|
7
6
|
|
|
8
7
|
module.exports = {
|
|
9
8
|
stringify: () => {
|
|
@@ -13,13 +12,13 @@ module.exports = {
|
|
|
13
12
|
at: [
|
|
14
13
|
() => {
|
|
15
14
|
const result = _.at(2)([1, 20, 300])
|
|
16
|
-
if (result ===
|
|
15
|
+
if (result === null) { throw result }
|
|
17
16
|
if (result[0] !== 300) { throw result }
|
|
18
17
|
},
|
|
19
18
|
|
|
20
19
|
() => {
|
|
21
20
|
const result = _.at(3)([1, 20, 300])
|
|
22
|
-
if (result !==
|
|
21
|
+
if (result !== null) { throw result }
|
|
23
22
|
}
|
|
24
23
|
],
|
|
25
24
|
first: [
|
|
@@ -29,7 +28,7 @@ module.exports = {
|
|
|
29
28
|
},
|
|
30
29
|
() => {
|
|
31
30
|
const result = _.first([])
|
|
32
|
-
if (result !==
|
|
31
|
+
if (result !== null) { throw result }
|
|
33
32
|
}
|
|
34
33
|
],
|
|
35
34
|
last: [
|
|
@@ -39,54 +38,51 @@ module.exports = {
|
|
|
39
38
|
},
|
|
40
39
|
() => {
|
|
41
40
|
const result = _.last([])
|
|
42
|
-
if (result !==
|
|
41
|
+
if (result !== null) { throw result }
|
|
43
42
|
}
|
|
44
43
|
],
|
|
45
44
|
head: [
|
|
46
45
|
() => {
|
|
47
46
|
const result = _.head([1, 20, 300])
|
|
48
|
-
if (result ===
|
|
47
|
+
if (result === null) { throw result }
|
|
49
48
|
const str = stringify(result)
|
|
50
49
|
if (str !== '[1,20]') { throw str }
|
|
51
50
|
},
|
|
52
51
|
() => {
|
|
53
52
|
const result = _.head([])
|
|
54
|
-
if (result !==
|
|
53
|
+
if (result !== null) { throw result }
|
|
55
54
|
}
|
|
56
55
|
],
|
|
57
56
|
tail: [
|
|
58
57
|
() => {
|
|
59
58
|
const result = _.tail([1, 20, 300])
|
|
60
|
-
if (result === undefined) { throw result }
|
|
61
59
|
const str = stringify(result)
|
|
62
60
|
if (str !== '[20,300]') { throw str }
|
|
63
61
|
},
|
|
64
62
|
() => {
|
|
65
63
|
const result = _.tail([])
|
|
66
|
-
if (result !==
|
|
64
|
+
if (result !== null) { throw result }
|
|
67
65
|
}
|
|
68
66
|
],
|
|
69
67
|
|
|
70
68
|
splitFirst: [
|
|
71
69
|
() => {
|
|
72
70
|
const result = _.splitFirst([1, 20, 300])
|
|
73
|
-
if (result === undefined) { throw result }
|
|
74
71
|
const str = stringify(result)
|
|
75
72
|
if (str !== '[1,[20,300]]') { throw str }
|
|
76
73
|
},
|
|
77
74
|
() => {
|
|
78
75
|
const result = _.splitFirst([])
|
|
79
|
-
if (result !==
|
|
76
|
+
if (result !== null) { throw result }
|
|
80
77
|
},
|
|
81
78
|
() => {
|
|
82
79
|
const result = _.splitLast([1, 20, 300])
|
|
83
|
-
if (result === undefined) { throw result }
|
|
84
80
|
const str = stringify(result)
|
|
85
81
|
if (str !== '[[1,20],300]') { throw str }
|
|
86
82
|
},
|
|
87
83
|
() => {
|
|
88
84
|
const result = _.splitLast([])
|
|
89
|
-
if (result !==
|
|
85
|
+
if (result !== null) { throw result }
|
|
90
86
|
}
|
|
91
87
|
]
|
|
92
88
|
}
|