functionalscript 0.0.484 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.484",
3
+ "version": "0.0.485",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ const _range = require('../../types/range/module.f.cjs')
3
3
  /** @type {(s: string) => (i: number) => number} */
4
4
  const at = s => i => {
5
5
  const r = s.codePointAt(i)
6
- if (r === undefined) { throw s }
6
+ if (r === void 0) { throw s }
7
7
  return r
8
8
  }
9
9
 
@@ -82,7 +82,7 @@ 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) ? undefined : { first, tail: () => at(i + 1) }
85
+ return isNaN(first) ? empty : { first, tail: () => at(i + 1) }
86
86
  }
87
87
  return at(0)
88
88
  }
@@ -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>(_: readonly T[]) => T|undefined} */
88
- const first = a => a[0]
87
+ /** @type {<T>(a: T|undefined) => T|null} */
88
+ const undefinedToNull = a => a === undefined ? null : a
89
89
 
90
- /** @type {<T>(_: readonly T[]) => T|undefined} */
91
- const last = a => a[a.length - 1]
90
+ /** @type {<T>(_: readonly T[]) => T|null} */
91
+ const first = a => undefinedToNull(a[0])
92
92
 
93
- /** @type {<T>(_: readonly T[]) => readonly T[] | undefined} */
94
- const tail = a => a.length === 0 ? undefined : uncheckTail(a)
93
+ /** @type {<T>(_: readonly T[]) => T|null} */
94
+ const last = a => undefinedToNull(a[a.length - 1])
95
95
 
96
- /** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|undefined} */
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[]|undefined} */
105
- const head = a => a.length === 0 ? undefined : uncheckHead(a)
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]|undefined} */
110
+ /** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|null} */
108
111
  const splitLast = a => {
109
112
  const lastA = last(a)
110
- if (lastA === undefined) { return undefined }
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]|undefined} */
115
- const at = index => a => index < a.length ? [a[index]] : undefined
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 */
@@ -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
- /** @type {(a: readonly json.Unknown[]) => string} */
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 === undefined) { throw 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 !== undefined) { throw 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 !== undefined) { throw 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 !== undefined) { throw 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 === undefined) { throw 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 !== undefined) { throw 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 !== undefined) { throw 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 !== undefined) { throw 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 !== undefined) { throw result }
85
+ if (result !== null) { throw result }
90
86
  }
91
87
  ]
92
88
  }