functionalscript 0.0.305 → 0.0.306
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
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
/** @type {(separator: string) => Fold<string>} */
|
|
14
14
|
const join = separator => prior => value => `${prior}${separator}${value}`
|
|
15
15
|
|
|
16
|
+
/** @type {Fold<string>} */
|
|
17
|
+
const concat = a => b => `${a}${b}`
|
|
18
|
+
|
|
16
19
|
/** @type {Fold<number>} */
|
|
17
20
|
const addition = a => b => a + b
|
|
18
21
|
|
|
@@ -26,8 +29,8 @@ const addition = a => b => a + b
|
|
|
26
29
|
const logicalNot = v => !v
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
|
-
* @template T
|
|
30
|
-
* @typedef {Binary<T, T, boolean>} Equal
|
|
32
|
+
* @template T
|
|
33
|
+
* @typedef {Binary<T, T, boolean>} Equal
|
|
31
34
|
*/
|
|
32
35
|
|
|
33
36
|
/** @type {<T>(a: T) => (b: T) => boolean} */
|
|
@@ -93,4 +96,6 @@ module.exports = {
|
|
|
93
96
|
foldToScan,
|
|
94
97
|
/** @readonly */
|
|
95
98
|
counter,
|
|
99
|
+
/** @readonly */
|
|
100
|
+
concat,
|
|
96
101
|
}
|
package/types/list/index.js
CHANGED
|
@@ -297,6 +297,20 @@ const equalZip = e => a => b => () => {
|
|
|
297
297
|
/** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => boolean} */
|
|
298
298
|
const equal = e => a => b => every(equalZip(e)(a)(b))
|
|
299
299
|
|
|
300
|
+
/** @type {(s: string) => List<number>} */
|
|
301
|
+
const toCharCodes = s => {
|
|
302
|
+
/** @type {(i: number) => List<number>} */
|
|
303
|
+
const at = i => () => {
|
|
304
|
+
const r = s.charCodeAt(i)
|
|
305
|
+
if (isNaN(r)) { return undefined }
|
|
306
|
+
return { first: r, tail: at(i + 1) }
|
|
307
|
+
}
|
|
308
|
+
return at(0)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** @type {(x: List<number>) => string} */
|
|
312
|
+
const fromCharCodes = x => fold(operator.concat)('')(map(String.fromCharCode)(x))
|
|
313
|
+
|
|
300
314
|
module.exports = {
|
|
301
315
|
/** @readonly */
|
|
302
316
|
empty: undefined,
|
|
@@ -374,4 +388,8 @@ module.exports = {
|
|
|
374
388
|
zip,
|
|
375
389
|
/** @readonly */
|
|
376
390
|
equal,
|
|
391
|
+
/** @readonly */
|
|
392
|
+
toCharCodes,
|
|
393
|
+
/** @readonly */
|
|
394
|
+
fromCharCodes,
|
|
377
395
|
}
|
package/types/list/test.js
CHANGED
|
@@ -234,6 +234,12 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
234
234
|
if (result !== false) { throw result }
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
{
|
|
238
|
+
const r = _.toCharCodes("Hello world!")
|
|
239
|
+
const x = _.fromCharCodes(r)
|
|
240
|
+
if (x !== "Hello world!") { throw x }
|
|
241
|
+
}
|
|
242
|
+
|
|
237
243
|
// stress tests
|
|
238
244
|
|
|
239
245
|
const stress = () => {
|