functionalscript 0.0.392 → 0.0.393

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.392",
3
+ "version": "0.0.393",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
package/test.f.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  const i = require('./module.f.cjs')
2
2
 
3
3
  require('./types/list/test.f.cjs')
4
+ require('./types/number/test.f.cjs')
5
+ require('./types/bigint/module.f.cjs')
4
6
  require('./types/array/test.f.cjs')
5
7
  require('./types/btree/test.f.cjs')
6
8
  require('./sha2/test.f.cjs')
@@ -0,0 +1,10 @@
1
+ const { fold } = require('../list/module.f.cjs')
2
+
3
+ /** @type {(a: bigint) => (b: bigint) => bigint} */
4
+ const addition = a => b => a + b
5
+
6
+ const sum = fold(addition)(0n)
7
+
8
+ module.exports = {
9
+ sum,
10
+ }
@@ -0,0 +1,8 @@
1
+ const { sum } = require('./module.f.cjs')
2
+
3
+ {
4
+ const result = sum([2n, 3n, 4n, 5n])
5
+ if (result !== 14n) { throw result }
6
+ }
7
+
8
+ module.exports = {}
@@ -16,11 +16,6 @@ const join = separator => value => prior => `${prior}${separator}${value}`
16
16
  /** @type {Fold<string>} */
17
17
  const concat = i => acc => `${acc}${i}`
18
18
 
19
- /** @type {Fold<number>} */
20
- const addition = a => b => a + b
21
-
22
- const increment = addition(1)
23
-
24
19
  /**
25
20
  * @template T
26
21
  * @template R
@@ -38,12 +33,6 @@ const logicalNot = v => !v
38
33
  /** @type {<T>(a: T) => (b: T) => boolean} */
39
34
  const strictEqual = a => b => a === b
40
35
 
41
- /** @type {Fold<number>} */
42
- const min = a => b => a < b ? a : b
43
-
44
- /** @type {Fold<number>} */
45
- const max = a => b => a > b ? a : b
46
-
47
36
  /**
48
37
  * @template I,O
49
38
  * @typedef {(input: I) => readonly[O, Scan<I,O>]} Scan
@@ -74,6 +63,17 @@ const reduceToScan = reduce => prior => i => {
74
63
  /** @type {<T>(fold: Fold<T>) => Scan<T, T>} */
75
64
  const foldToScan = op => init => [init, reduceToScan(op)(init)]
76
65
 
66
+ /** @type {Fold<number>} */
67
+ const addition = a => b => a + b
68
+
69
+ /** @type {Fold<number>} */
70
+ const min = a => b => a < b ? a : b
71
+
72
+ /** @type {Fold<number>} */
73
+ const max = a => b => a > b ? a : b
74
+
75
+ const increment = addition(1)
76
+
77
77
  const counter = () => increment
78
78
 
79
79
  module.exports = {
@@ -1,17 +1,14 @@
1
1
  const { compose, identity } = require('../function/module.f.cjs')
2
2
  const operator = require('../function/operator/module.f.cjs')
3
- const {
4
- addition,
5
- min: minOp,
6
- max: maxOp,
7
- join: joinOp,
8
- concat: concatOp,
3
+ const {
4
+ join: joinOp,
5
+ concat: concatOp,
9
6
  counter,
10
- logicalNot,
11
- strictEqual,
12
- stateScanToScan,
13
- reduceToScan,
14
- foldToScan
7
+ logicalNot,
8
+ strictEqual,
9
+ stateScanToScan,
10
+ reduceToScan,
11
+ foldToScan
15
12
  } = operator
16
13
 
17
14
  /**
@@ -264,12 +261,6 @@ const reduce = op => init => input => last(init)(reduceScan(op)(init)(input))
264
261
  /** @type {<T>(op: operator.Fold<T>) => <D>(def: D) => (input: List<T>) => D|T} */
265
262
  const fold = op => def => input => last(def)(scan(foldToScan(op))(input))
266
263
 
267
- const sum = fold(addition)(0)
268
-
269
- const min = fold(minOp)(undefined)
270
-
271
- const max = fold(maxOp)(undefined)
272
-
273
264
  /** @type {(separator: string) => (input: List<string>) => string} */
274
265
  const join = separator => fold(joinOp(separator))('')
275
266
 
@@ -380,12 +371,6 @@ module.exports = {
380
371
  /** @readonly */
381
372
  fold,
382
373
  /** @readonly */
383
- sum,
384
- /** @readonly */
385
- min,
386
- /** @readonly */
387
- max,
388
- /** @readonly */
389
374
  join,
390
375
  /** @readonly */
391
376
  stringConcat,
@@ -99,11 +99,6 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
99
99
  if (result !== '[2,5,9,14]') { throw result }
100
100
  }
101
101
 
102
- {
103
- const result = _.sum([2, 3, 4, 5])
104
- if (result !== 14) { throw result }
105
- }
106
-
107
102
  {
108
103
  const result = _.fold(addition)(undefined)([2, 3, 4, 5])
109
104
  if (result !== 14) { throw result }
@@ -211,21 +206,6 @@ const map5 = _.map(x => x > 5)
211
206
  if (!result) { throw result }
212
207
  }
213
208
 
214
- {
215
- const result = _.min([])
216
- if (result !== undefined) { throw result }
217
- }
218
-
219
- {
220
- const result = _.min([1, 2, 12, -4, 8])
221
- if (result !== -4) { throw result }
222
- }
223
-
224
- {
225
- const result = _.max([1, 2, 12, -4, 8])
226
- if (result !== 12) { throw result }
227
- }
228
-
229
209
  {
230
210
  const result = _.isEmpty(() => [])
231
211
  if (result !== true) { throw result }
@@ -0,0 +1,17 @@
1
+ const { fold } = require('../list/module.f.cjs')
2
+ const { addition, min: minOp, max: maxOp } = require('../function/operator/module.f.cjs')
3
+
4
+ const sum = fold(addition)(0)
5
+
6
+ const min = fold(minOp)(undefined)
7
+
8
+ const max = fold(maxOp)(undefined)
9
+
10
+ module.exports = {
11
+ /** @readonly */
12
+ sum,
13
+ /** @readonly */
14
+ min,
15
+ /** @readonly */
16
+ max,
17
+ }
@@ -0,0 +1,23 @@
1
+ const { sum, min, max } = require('./module.f.cjs')
2
+
3
+ {
4
+ const result = sum([2, 3, 4, 5])
5
+ if (result !== 14) { throw result }
6
+ }
7
+
8
+ {
9
+ const result = min([])
10
+ if (result !== undefined) { throw result }
11
+ }
12
+
13
+ {
14
+ const result = min([1, 2, 12, -4, 8])
15
+ if (result !== -4) { throw result }
16
+ }
17
+
18
+ {
19
+ const result = max([1, 2, 12, -4, 8])
20
+ if (result !== 12) { throw result }
21
+ }
22
+
23
+ module.exports = {}