functionalscript 0.0.386 → 0.0.389

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/doc/vm.md CHANGED
@@ -23,14 +23,12 @@
23
23
  |`_` |`\x5F` | 1| 26|
24
24
  |`a`..`z`|`\x61`..`\x7A`|1A| 40|
25
25
 
26
- ## 64 bit platform
26
+ ## Value
27
27
 
28
28
  Alignment: 8 bytes.
29
29
 
30
30
  Pointer: 2^64 / 2^3 = 2^61 bit
31
31
 
32
- ### Value
33
-
34
32
  - `63`: 9 x 7 bit string
35
33
  - `63`:
36
34
  - `61`: pointer + null, alignment - 8 bytes
package/html/module.f.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  const list = require('../types/list/module.f.cjs')
2
2
  const object = require('../types/object/module.f.cjs')
3
3
  const { operator, compose } = require('../types/function/module.f.cjs')
4
+ const encoding = require('../text/encoding/module.f.cjs');
4
5
 
5
6
  /**
6
7
  * @typedef {|
@@ -73,7 +74,7 @@ const escapeCharCode = code => {
73
74
  }
74
75
  }
75
76
 
76
- const escape = compose(list.toCharCodeList)(list.map(escapeCharCode))
77
+ const escape = compose(encoding.stringToUtf16List)(list.map(escapeCharCode))
77
78
 
78
79
  /** @type {(n: Node) => list.List<string>} */
79
80
  const node = n => typeof n === 'string' ? escape(n) : element(n)
@@ -2,9 +2,10 @@ const tokenizer = require('./module.f.cjs')
2
2
  const list = require('../../types/list/module.f.cjs')
3
3
  const json = require('../module.f.cjs')
4
4
  const { sort } = require('../../types/object/module.f.cjs')
5
+ const encoding = require('../../text/encoding/module.f.cjs');
5
6
 
6
7
  /** @type {(s: string) => readonly tokenizer.JsonToken[]} */
7
- const tokenizeString = s => list.toArray(tokenizer.tokenize(list.toCharCodeList(s)))
8
+ const tokenizeString = s => list.toArray(tokenizer.tokenize(encoding.stringToUtf16List(s)))
8
9
 
9
10
  const stringify = json.stringify(sort)
10
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.386",
3
+ "version": "0.0.389",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -4,14 +4,14 @@
4
4
 
5
5
  Requirement: no loss for UTF8 => codepoint => UTF8
6
6
 
7
- |utf8 |codepoint |size |codepoint |
7
+ |utf8 |utf8 code |size |codepoint |
8
8
  |---------|---------------------------------------|---------|--------------------------------------------------|
9
9
  |[a] |0xxx_xxxx |7 bit |0_0000_0000_0000_0xxx_xxxx |
10
10
  |[b,a] |110x_xxxx 10xx_xxxx |11 bit |0_0000_0000_0xxx_xxxx_xxxx + 0_0000_0000_1000_0000|
11
11
  |[c,b,a] |1110_xxxx 10xx_xxxx 10xx_xxxx |16 bit |0_0000_xxxx_xxxx_xxxx_xxxx + 0_0000_1000_0000_0000|
12
12
  |[d,c,b,a]|1111_0xxx 10xx_xxxx 10xx_xxxx 10xx_xxxx|21 bit |x_xxxx_xxxx_xxxx_xxxx_xxxx + 1_0000_0000_0000_0000|
13
13
 
14
- |utf8 error| |size |codepoint |
14
+ |utf8 error|utf8 code |size |codepoint |
15
15
  |----------|-----------------------------|------|-------------------|
16
16
  |[e] |1111_1xxx | 3 bit| |
17
17
  |[d,] |1111_0xxx | 3 bit| |
@@ -55,15 +55,15 @@ Requirement: no loss for UTF16 => codepoint => UTF16
55
55
  - first : 0xD800: 0b_1101_10xx_xxxx_xxxx : 10 bit
56
56
  - second: 0xDC00: 0b_1101_11xx_xxxx_xxxx : 10 bit
57
57
 
58
- |utf16 |codepoint |size |
59
- |---------|---------------------------------------|------|
60
- |[a] |xxxx_xxxx_xxxx_xxxx |16 bit|
61
- |[b,a] |1101_10xx_xxxx_xxxx 1101_11xx_xxxx_xxxx|20 bit|
58
+ |utf16 |utf16 code |size |codepoint |
59
+ |---------|---------------------------------------|------|------------------------------------------------|
60
+ |[a] |xxxx_xxxx_xxxx_xxxx |16 bit|0000_xxxx_xxxx_xxxx_xxxx |
61
+ |[b,a] |1101_10xx_xxxx_xxxx 1101_11xx_xxxx_xxxx|20 bit|xxxx_xxxx_xxxx_xxxx_xxxx + 1_0000_0000_0000_0000|
62
62
 
63
- |utf16 error|codepoint |size |
64
- |-----------|-------------------|------|
65
- |[e] |1101_11xx_xxxx_xxxx|10 bit|
66
- |[b,] |1101_10xx_xxxx_xxxx|10 bit|
63
+ |utf16 error|utf16 code |size |codepoint |
64
+ |-----------|-------------------|------|-------------------|
65
+ |[e] |1101_11xx_xxxx_xxxx|10 bit|1101_11xx_xxxx_xxxx|
66
+ |[b,] |1101_10xx_xxxx_xxxx|10 bit|1101_10xx_xxxx_xxxx|
67
67
 
68
68
  Total error states: 11 bit
69
69
 
@@ -74,7 +74,7 @@ const utf16ListToCodePointList
74
74
  /** @type {(input: List<i32>) => List<u16>} */
75
75
  const codePointListToUtf16List
76
76
 
77
- /** @type {(input: string) => List<u16> */
77
+ /** @type {(input: string) => List<u16>} */
78
78
  const stringToUtf16List
79
79
 
80
80
  /** @type {(input: List<u16>) => string} */
@@ -3,6 +3,8 @@ const list = require('../../types/list/module.f.cjs')
3
3
  const operator = require('../../types/function/operator/module.f.cjs')
4
4
  const array = require('../../types/array/module.f.cjs')
5
5
  const { contains } = require('../../types/range/module.f.cjs')
6
+ const { compose } = require('../../types/function/module.f.cjs')
7
+ const { map, flat, stateScan, concat, fold, toArray, flatMap } = list
6
8
  const { ok, error } = result
7
9
 
8
10
  /** @typedef {result.Result<number,number>} ByteResult */
@@ -11,9 +13,15 @@ const { ok, error } = result
11
13
 
12
14
  /** @typedef {number|undefined} ByteOrEof */
13
15
 
16
+ /** @typedef {u16|undefined} WordOrEof */
17
+
14
18
  /** @typedef {undefined|array.Array1<number>|array.Array2<number>|array.Array3<number>} Utf8State */
15
19
 
16
- /** @typedef {undefined|array.Array1<number>|array.Array2<number>|array.Array3<number>} Utf16State */
20
+ /** @typedef {undefined|number} Utf16State */
21
+
22
+ /** @typedef {number} u16 */
23
+
24
+ /** @typedef {number} i32 */
17
25
 
18
26
  /** @type {(a:number) => boolean} */
19
27
  const isBmpCodePoint = a => a >= 0x0000 && a <= 0xd7ff || a >= 0xe000 && a <= 0xffff
@@ -23,6 +31,8 @@ const isHighSurrogate = contains([0xd800, 0xdbff])
23
31
  /** @type {(a:number) => boolean} */
24
32
  const isLowSurrogate = contains([0xdc00, 0xdfff])
25
33
 
34
+ const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000
35
+
26
36
  /** @type {(input:number) => list.List<ByteResult>} */
27
37
  const codePointToUtf8 = input =>
28
38
  {
@@ -33,29 +43,29 @@ const codePointToUtf8 = input =>
33
43
  return [error(input)]
34
44
  }
35
45
 
36
- /** @type {(input:number) => list.List<ByteResult>} */
46
+ /** @type {(input:i32) => list.List<u16>} */
37
47
  const codePointToUtf16 = input =>
38
48
  {
39
- if (isBmpCodePoint(input)) { return [ok(input >> 8), ok(input & 0xff)] }
49
+ if (isBmpCodePoint(input)) { return [input] }
40
50
  if (input >= 0x010000 && input <= 0x10ffff) {
41
51
  const high = ((input - 0x10000) >> 10) + 0xd800
42
- const low = ((input - 0x10000) & 0x3ff) + 0xdc00
43
- return [ok(high >> 8), ok(high & 0xff), ok(low >> 8), ok(low & 0xff)]
52
+ const low = ((input - 0x10000) & 0b0011_1111_1111) + 0xdc00
53
+ return [high, low]
44
54
  }
45
- return [error(input)]
55
+ return [input & 0xffff]
46
56
  }
47
57
 
48
58
  /** @type {(input: list.List<number>) => list.List<ByteResult>} */
49
- const codePointListToUtf8 = list.flatMap(codePointToUtf8)
59
+ const codePointListToUtf8List = flatMap(codePointToUtf8)
50
60
 
51
- /** @type {(input: list.List<number>) => list.List<ByteResult>} */
52
- const codePointListToUtf16 = list.flatMap(codePointToUtf16)
61
+ /** @type {(input: list.List<i32>) => list.List<u16>} */
62
+ const codePointListToUtf16List = flatMap(codePointToUtf16)
53
63
 
54
64
  /** @type {operator.StateScan<number, Utf8State, list.List<CodePointResult>>} */
55
65
  const utf8ByteToCodePointOp = state => byte => {
56
66
  if (byte < 0x00 || byte > 0xff) {
57
67
  return [[error([byte])], state]
58
- }
68
+ }
59
69
  if (state == undefined) {
60
70
  if (byte < 0x80) { return [[ok(byte)], undefined] }
61
71
  if (byte >= 0xc2 && byte <= 0xf4) { return [[], [byte]] }
@@ -68,71 +78,79 @@ const utf8ByteToCodePointOp = state => byte => {
68
78
  case 1:
69
79
  if (state[0] < 0xe0) { return [[ok(((state[0] & 0x1f) << 6) + (byte & 0x3f))], undefined] }
70
80
  if (state[0] < 0xf8) { return [[], [state[0], byte]] }
71
- break
81
+ break
72
82
  case 2:
73
83
  if (state[0] < 0xf0) { return [[ok(((state[0] & 0x0f) << 12) + ((state[1] & 0x3f) << 6) + (byte & 0x3f))], undefined] }
74
84
  if (state[0] < 0xf8) { return [[], [state[0], state[1], byte]] }
75
85
  break
76
- case 3:
86
+ case 3:
77
87
  return [[ok(((state[0] & 0x07) << 18) + ((state[1] & 0x3f) << 12) + ((state[2] & 0x3f) << 6) + (byte & 0x3f))], undefined]
78
88
  }
79
- }
80
- return [[error(list.toArray(list.concat(state)([byte])))], undefined]
89
+ }
90
+ return [[error(toArray(concat(state)([byte])))], undefined]
81
91
  }
82
92
 
83
93
  /** @type {(state: Utf8State) => readonly[list.List<CodePointResult>, Utf8State]} */
84
- const utf8EofToCodePointOp = state => [state == undefined ? undefined : [error(state)], undefined]
94
+ const utf8EofToCodePointOp = state => [state === undefined ? undefined : [error(state)], undefined]
85
95
 
86
96
  /** @type {operator.StateScan<ByteOrEof, Utf8State, list.List<CodePointResult>>} */
87
97
  const utf8ByteOrEofToCodePointOp = state => input => input === undefined ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input)
88
98
 
89
99
  /** @type {(input: list.List<number>) => list.List<CodePointResult>} */
90
- const utf8ListToCodePoint = input => list.flat(list.stateScan(utf8ByteOrEofToCodePointOp)(undefined)(list.concat(/** @type {list.List<ByteOrEof>} */(input))([undefined])))
100
+ const utf8ListToCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(undefined)(concat(/** @type {list.List<ByteOrEof>} */(input))([undefined])))
91
101
 
92
- /** @type {operator.StateScan<number, Utf16State, list.List<CodePointResult>>} */
102
+ /** @type {operator.StateScan<u16, Utf16State, list.List<i32>>} */
93
103
  const utf16ByteToCodePointOp = state => byte => {
94
- if (byte < 0x00 || byte > 0xff) {
95
- return [[error([byte])], state]
104
+ if (byte < 0x00 || byte > 0xffff) {
105
+ return [[0xffffffff], state]
96
106
  }
97
- if (state == undefined) {
98
- return [[], [byte]]
107
+ if (state === undefined) {
108
+ if (isBmpCodePoint(byte)) { return [[byte], undefined] }
109
+ if (isHighSurrogate(byte)) { return [[], byte] }
110
+ return [[byte | errorMask], undefined]
99
111
  }
100
- switch(state.length)
101
- {
102
- case 1:
103
- const codeUnit = (state[0] << 8) + byte
104
- if (isBmpCodePoint(codeUnit)) { return [[ok(codeUnit)], undefined] }
105
- if (isHighSurrogate(codeUnit)) { return [[], [state[0], byte]] }
106
- break
107
- case 2:
108
- return [[], [state[0], state[1], byte]]
109
- case 3:
110
- if (isLowSurrogate((state[2] << 8) + byte)) {
111
- const high = (state[0] << 8) + state[1] - 0xd800
112
- const low = (state[2] << 8) + byte - 0xdc00
113
- return [[ok((high << 10) + low + 0x10000)], undefined]
114
- }
115
- break
112
+ if (isLowSurrogate(byte)) {
113
+ const high = state - 0xd800
114
+ const low = byte - 0xdc00
115
+ return [[(high << 10) + low + 0x10000], undefined]
116
116
  }
117
- return [[error(list.toArray(list.concat(state)([byte])))], undefined]
117
+ if (isBmpCodePoint(byte)) { return [[state | errorMask, byte], undefined] }
118
+ if (isHighSurrogate(byte)) { return [[state | errorMask], byte] }
119
+ return [[state | errorMask, byte | errorMask], undefined]
118
120
  }
119
121
 
120
- /** @type {(state: Utf8State) => readonly[list.List<CodePointResult>, Utf16State]} */
121
- const utf16EofToCodePointOp = state => [state == undefined ? undefined : [error(state)], undefined]
122
+ /** @type {(state: Utf16State) => readonly[list.List<i32>, Utf16State]} */
123
+ const utf16EofToCodePointOp = state => [state === undefined ? undefined : [state | errorMask], undefined]
122
124
 
123
- /** @type {operator.StateScan<ByteOrEof, Utf8State, list.List<CodePointResult>>} */
125
+ /** @type {operator.StateScan<WordOrEof, Utf16State, list.List<i32>>} */
124
126
  const utf16ByteOrEofToCodePointOp = state => input => input === undefined ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input)
125
127
 
126
- /** @type {(input: list.List<number>) => list.List<CodePointResult>} */
127
- const utf16ListToCodePoint = input => list.flat(list.stateScan(utf16ByteOrEofToCodePointOp)(undefined)(list.concat(/** @type {list.List<ByteOrEof>} */(input))([undefined])))
128
+ /** @type {(input: list.List<u16>) => list.List<i32>} */
129
+ const utf16ListToCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(undefined)(concat(/** @type {list.List<WordOrEof>} */(input))([undefined])))
130
+
131
+ /** @type {(s: string) => list.List<u16>} */
132
+ const stringToUtf16List = s => {
133
+ /** @type {(i: number) => list.Result<number>} */
134
+ const at = i => {
135
+ const first = s.charCodeAt(i)
136
+ return isNaN(first) ? undefined : { first, tail: () => at(i + 1) }
137
+ }
138
+ return at(0)
139
+ }
140
+
141
+ const utf16ListToString = compose(map(String.fromCharCode))(fold(operator.concat)(''))
128
142
 
129
143
  module.exports = {
130
144
  /** @readonly */
131
- codePointListToUtf8,
145
+ codePointListToUtf8List,
146
+ /** @readonly */
147
+ codePointListToUtf16List,
148
+ /** @readonly */
149
+ utf8ListToCodePointList,
132
150
  /** @readonly */
133
- codePointListToUtf16,
151
+ utf16ListToCodePointList,
134
152
  /** @readonly */
135
- utf8ListToCodePoint,
153
+ stringToUtf16List,
136
154
  /** @readonly */
137
- utf16ListToCodePoint
155
+ utf16ListToString
138
156
  }
@@ -7,193 +7,217 @@ const { list } = require('../../types/module.f.cjs')
7
7
  const stringify = a => json.stringify(sort)(a)
8
8
 
9
9
  {
10
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0,1,0x7F])))
10
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0,1,0x7F])))
11
11
  if (result !== '[["ok",0],["ok",1],["ok",127]]') { throw result }
12
12
  }
13
13
 
14
14
  {
15
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x80])))
15
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x80])))
16
16
  if (result !== '[["ok",194],["ok",128]]') { throw result }
17
17
  }
18
18
 
19
19
  {
20
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0xa9])))
20
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0xa9])))
21
21
  if (result !== '[["ok",194],["ok",169]]') { throw result }
22
22
  }
23
23
 
24
24
  {
25
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x7ff])))
25
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x7ff])))
26
26
  if (result !== '[["ok",223],["ok",191]]') { throw result }
27
27
  }
28
28
 
29
29
  {
30
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x800])))
30
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x800])))
31
31
  if (result !== '[["ok",224],["ok",160],["ok",128]]') { throw result }
32
32
  }
33
33
 
34
34
  {
35
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x801])))
35
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x801])))
36
36
  if (result !== '[["ok",224],["ok",160],["ok",129]]') { throw result }
37
37
  }
38
38
 
39
39
  {
40
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0xffff])))
40
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0xffff])))
41
41
  if (result !== '[["ok",239],["ok",191],["ok",191]]') { throw result }
42
42
  }
43
43
 
44
44
  {
45
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x10000])))
45
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x10000])))
46
46
  if (result !== '[["ok",240],["ok",144],["ok",128],["ok",128]]') { throw result }
47
47
  }
48
48
 
49
49
  {
50
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x10001])))
50
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x10001])))
51
51
  if (result !== '[["ok",240],["ok",144],["ok",128],["ok",129]]') { throw result }
52
52
  }
53
53
 
54
54
  {
55
- const result = stringify(list.toArray(encoding.codePointListToUtf8([0x10FFFF])))
55
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([0x10FFFF])))
56
56
  if (result !== '[["ok",244],["ok",143],["ok",191],["ok",191]]') { throw result }
57
57
  }
58
58
 
59
59
  {
60
- const result = stringify(list.toArray(encoding.codePointListToUtf8([-1,0x110000])))
60
+ const result = stringify(list.toArray(encoding.codePointListToUtf8List([-1,0x110000])))
61
61
  if (result !== '[["error",-1],["error",1114112]]') { throw result }
62
62
  }
63
63
 
64
64
  {
65
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0])))
66
- if (result !== '[["ok",0],["ok",0]]') { throw result }
65
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0])))
66
+ if (result !== '[0]') { throw result }
67
67
  }
68
68
 
69
69
  {
70
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0x24])))
71
- if (result !== '[["ok",0],["ok",36]]') { throw result }
70
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0x24])))
71
+ if (result !== '[36]') { throw result }
72
72
  }
73
73
 
74
74
  {
75
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0x20AC])))
76
- if (result !== '[["ok",32],["ok",172]]') { throw result }
75
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0x20AC])))
76
+ if (result !== '[8364]') { throw result }
77
77
  }
78
78
 
79
79
  {
80
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0xd7ff])))
81
- if (result !== '[["ok",215],["ok",255]]') { throw result }
80
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0xd7ff])))
81
+ if (result !== '[55295]') { throw result }
82
82
  }
83
83
 
84
84
  {
85
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0xe000])))
86
- if (result !== '[["ok",224],["ok",0]]') { throw result }
85
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0xe000])))
86
+ if (result !== '[57344]') { throw result }
87
87
  }
88
88
 
89
89
  {
90
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0xffff])))
91
- if (result !== '[["ok",255],["ok",255]]') { throw result }
90
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0xffff])))
91
+ if (result !== '[65535]') { throw result }
92
92
  }
93
93
 
94
94
  {
95
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0x10000])))
96
- if (result !== '[["ok",216],["ok",0],["ok",220],["ok",0]]') { throw result }
95
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0x10000])))
96
+ if (result !== '[55296,56320]') { throw result }
97
97
  }
98
98
 
99
99
  {
100
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0x10437])))
101
- if (result !== '[["ok",216],["ok",1],["ok",220],["ok",55]]') { throw result }
100
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0x10437])))
101
+ if (result !== '[55297,56375]') { throw result }
102
102
  }
103
103
 
104
104
  {
105
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0x24B62])))
106
- if (result !== '[["ok",216],["ok",82],["ok",223],["ok",98]]') { throw result }
105
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0x24B62])))
106
+ if (result !== '[55378,57186]') { throw result }
107
107
  }
108
108
 
109
109
  {
110
- const result = stringify(list.toArray(encoding.codePointListToUtf16([0x10ffff])))
111
- if (result !== '[["ok",219],["ok",255],["ok",223],["ok",255]]') { throw result }
110
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([0x10ffff])))
111
+ if (result !== '[56319,57343]') { throw result }
112
112
  }
113
113
 
114
114
  {
115
- const result = stringify(list.toArray(encoding.codePointListToUtf16([-1, 0xd800, 0xdfff, 0x110000])))
116
- if (result !== '[["error",-1],["error",55296],["error",57343],["error",1114112]]') { throw result }
115
+ const result = stringify(list.toArray(encoding.codePointListToUtf16List([-1, 0xd800, 0xdfff, 0x110000])))
116
+ if (result !== '[65535,55296,57343,0]') { throw result }
117
117
  }
118
118
 
119
- {
120
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([-1, 256])))
119
+ {
120
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([-1, 256])))
121
121
  if (result !== '[["error",[-1]],["error",[256]]]') { throw result }
122
122
  }
123
123
 
124
- {
125
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([128, 193, 245, 255])))
124
+ {
125
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([128, 193, 245, 255])))
126
126
  if (result !== '[["error",[128]],["error",[193]],["error",[245]],["error",[255]]]') { throw result }
127
127
  }
128
128
 
129
- {
130
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([0, 1, 127])))
129
+ {
130
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([0, 1, 127])))
131
131
  if (result !== '[["ok",0],["ok",1],["ok",127]]') { throw result }
132
132
  }
133
133
 
134
134
  {
135
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([194, 128, 194, 169, 223, 191])))
135
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([194, 128, 194, 169, 223, 191])))
136
136
  if (result !== '[["ok",128],["ok",169],["ok",2047]]') { throw result }
137
137
  }
138
138
 
139
- {
140
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([194, 127, 194, 192, 194])))
139
+ {
140
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([194, 127, 194, 192, 194])))
141
141
  if (result !== '[["error",[194,127]],["error",[194,192]],["error",[194]]]') { throw result }
142
142
  }
143
143
 
144
144
  {
145
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([224, 160, 128, 224, 160, 129, 239, 191, 191])))
145
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([224, 160, 128, 224, 160, 129, 239, 191, 191])))
146
146
  if (result !== '[["ok",2048],["ok",2049],["ok",65535]]') { throw result }
147
147
  }
148
148
 
149
- {
150
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([224, 160, 127, 224, 160, 192, 224, 160])))
149
+ {
150
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([224, 160, 127, 224, 160, 192, 224, 160])))
151
151
  if (result !== '[["error",[224,160,127]],["error",[224,160,192]],["error",[224,160]]]') { throw result }
152
152
  }
153
153
 
154
154
  {
155
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([240, 144, 128, 128, 240, 144, 128, 129, 244, 143, 191, 191])))
155
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([240, 144, 128, 128, 240, 144, 128, 129, 244, 143, 191, 191])))
156
156
  if (result !== '[["ok",65536],["ok",65537],["ok",1114111]]') { throw result }
157
157
  }
158
158
 
159
- {
160
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([240, 144, 128, 127, 240, 144, 128, 192, 240, 144, 128])))
159
+ {
160
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([240, 144, 128, 127, 240, 144, 128, 192, 240, 144, 128])))
161
161
  if (result !== '[["error",[240,144,128,127]],["error",[240,144,128,192]],["error",[240,144,128]]]') { throw result }
162
162
  }
163
163
 
164
164
  {
165
- const result = stringify(list.toArray(encoding.utf8ListToCodePoint([194, -1, 128])))
165
+ const result = stringify(list.toArray(encoding.utf8ListToCodePointList([194, -1, 128])))
166
166
  if (result !== '[["error",[-1]],["ok",128]]') { throw result }
167
167
  }
168
168
 
169
- {
170
- const result = stringify(list.toArray(encoding.utf16ListToCodePoint([-1, 256,])))
171
- if (result !== '[["error",[-1]],["error",[256]]]') { throw result }
169
+ {
170
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([-1, 65536])))
171
+ if (result !== '[4294967295,4294967295]') { throw result }
172
+ }
173
+
174
+ {
175
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([0, 36, 8364, 55295, 57344, 65535])))
176
+ if (result !== '[0,36,8364,55295,57344,65535]') { throw result }
177
+ }
178
+
179
+ {
180
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([56320, 57343])))
181
+ if (result !== '[-2147427328,-2147426305]') { throw result }
182
+ }
183
+
184
+ {
185
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([55296, 56320, 55297, 56375, 55378, 57186, 56319, 57343])))
186
+ if (result !== '[65536,66615,150370,1114111]') { throw result }
187
+ }
188
+
189
+ {
190
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([55296, 55296])))
191
+ if (result !== '[-2147428352,-2147428352]') { throw result }
172
192
  }
173
193
 
174
194
  {
175
- const result = stringify(list.toArray(encoding.utf16ListToCodePoint([0, 0, 0, 36, 32, 172, 215, 255, 224, 0, 255, 255])))
176
- if (result !== '[["ok",0],["ok",36],["ok",8364],["ok",55295],["ok",57344],["ok",65535]]') { throw result }
195
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([55296, 0])))
196
+ if (result !== '[-2147428352,0]') { throw result }
177
197
  }
178
198
 
179
199
  {
180
- const result = stringify(list.toArray(encoding.utf16ListToCodePoint([220, 0, 223, 255])))
181
- if (result !== '[["error",[220,0]],["error",[223,255]]]') { throw result }
200
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([56320])))
201
+ if (result !== '[-2147427328]') { throw result }
182
202
  }
183
203
 
184
204
  {
185
- const result = stringify(list.toArray(encoding.utf16ListToCodePoint([216, 0, 220, 0, 216, 1, 220, 55, 216, 82, 223, 98, 219, 255, 223, 255])))
186
- if (result !== '[["ok",65536],["ok",66615],["ok",150370],["ok",1114111]]') { throw result }
205
+ const result = stringify(list.toArray(encoding.utf16ListToCodePointList([56320, 0])))
206
+ if (result !== '[-2147427328,0]') { throw result }
187
207
  }
188
208
 
189
209
  {
190
- const result = stringify(list.toArray(encoding.utf16ListToCodePoint([216, 0, 216, 0])))
191
- if (result !== '[["error",[216,0,216,0]]]') { throw result }
210
+ const utf16List = encoding.stringToUtf16List("Hello world!😂🚜🚲")
211
+ const result = encoding.utf16ListToString(utf16List)
212
+ if (result !== "Hello world!😂🚜🚲") { throw result }
192
213
  }
193
214
 
194
215
  {
195
- const result = stringify(list.toArray(encoding.utf16ListToCodePoint([216, 0, 0, 0])))
196
- if (result !== '[["error",[216,0,0,0]]]') { throw result }
216
+ const a = encoding.stringToUtf16List("Hello world!😂🚜🚲")
217
+ const b = encoding.utf16ListToCodePointList(a)
218
+ const c = encoding.codePointListToUtf16List(b)
219
+ const result = encoding.utf16ListToString(c)
220
+ if (result !== "Hello world!😂🚜🚲") { throw result }
197
221
  }
198
222
 
199
223
  module.exports = {}
@@ -296,18 +296,6 @@ const equalZip = e => a => b => () => {
296
296
  /** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => boolean} */
297
297
  const equal = e => a => b => every(equalZip(e)(a)(b))
298
298
 
299
- /** @type {(s: string) => List<number>} */
300
- const toCharCodeList = s => {
301
- /** @type {(i: number) => Result<number>} */
302
- const at = i => {
303
- const first = s.charCodeAt(i)
304
- return isNaN(first) ? undefined : { first, tail: () => at(i + 1) }
305
- }
306
- return at(0)
307
- }
308
-
309
- const fromCharCodeList = compose(map(String.fromCharCode))(fold(operator.concat)(''))
310
-
311
299
  module.exports = {
312
300
  /** @readonly */
313
301
  empty: undefined,
@@ -384,9 +372,5 @@ module.exports = {
384
372
  /** @readonly */
385
373
  zip,
386
374
  /** @readonly */
387
- equal,
388
- /** @readonly */
389
- toCharCodeList,
390
- /** @readonly */
391
- fromCharCodeList,
375
+ equal
392
376
  }
@@ -236,11 +236,7 @@ const map5 = _.map(x => x > 5)
236
236
  if (result !== false) { throw result }
237
237
  }
238
238
 
239
- {
240
- const r = _.toCharCodeList("Hello world!")
241
- const x = _.fromCharCodeList(r)
242
- if (x !== "Hello world!") { throw x }
243
- }
239
+
244
240
 
245
241
  // stress tests
246
242