functionalscript 0.0.194 → 0.0.197

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/btree/index.js CHANGED
@@ -339,8 +339,8 @@ module.exports = {
339
339
  * @type { <T>(cmp: Cmp<T>) => (node: Node<T>) => T|undefined }
340
340
  */
341
341
  getVisitor: cmp => node => {
342
- const result = visit(getVisitor)(cmp)(() => { throw '' })(node)
343
- if ('done' in result && result.done) { return result.value }
342
+ const _0 = visit(getVisitor)(cmp)(() => { throw '' })(node)
343
+ if ('done' in _0 && _0.done) { return _0.value }
344
344
  return undefined
345
345
  },
346
346
  /** @readonly */
package/btree/test.js CHANGED
@@ -13,18 +13,18 @@ const set = node => value => {
13
13
 
14
14
  const test = () => {
15
15
  /** @type {btree.Node<string>} */
16
- let node = ['a']
17
- node = set(node)('b')
18
- node = set(node)('c')
19
- node = set(node)('d')
20
- node = set(node)('e')
21
- node = set(node)('f')
16
+ let _map = ['a']
17
+ _map = set(_map)('b')
18
+ _map = set(_map)('c')
19
+ _map = set(_map)('d')
20
+ _map = set(_map)('e')
21
+ _map = set(_map)('f')
22
22
  //
23
23
  {
24
24
  /** @type {import('../sequence').Result<string>} */
25
- let result = list.next(valuesList(node))
26
- while (result !== undefined) {
27
- result = list.next(result[1])
25
+ let _item = list.next(valuesList(_map))
26
+ while (_item !== undefined) {
27
+ _item = list.next(_item[1])
28
28
  }
29
29
  }
30
30
  }
package/cmp/index.js CHANGED
@@ -18,8 +18,8 @@ const index3 = cmp => value => /** @type {Index3} */ (cmp(value) + 1)
18
18
 
19
19
  /** @type {<T>(cmp: Cmp<T>) => (v2: Array2<T>) => Index5} */
20
20
  const index5 = cmp => ([v0, v1]) => {
21
- const cmpV0 = cmp(v0)
22
- return /** @type {Index5} */ (cmpV0 <= 0 ? cmpV0 + 1 : cmp(v1) + 3)
21
+ const _0 = cmp(v0)
22
+ return /** @type {Index5} */ (_0 <= 0 ? _0 + 1 : cmp(v1) + 3)
23
23
  }
24
24
 
25
25
  /** @type {(a: string) => (b: string) => Sign} */
package/json/index.js CHANGED
@@ -2,6 +2,7 @@ const seq = require('../sequence')
2
2
  const map = require('../map')
3
3
  const op = require('../sequence/operator')
4
4
  const option = require('../option')
5
+ const array = require('../sequence/array')
5
6
 
6
7
  /**
7
8
  * @typedef {{
@@ -23,7 +24,7 @@ const addProperty = value => {
23
24
  const [name, tail] = result
24
25
  return { ...srcObject, [name]: f(tail)(srcObject[name]) }
25
26
  }
26
- return path => f(seq.fromArray(path))
27
+ return path => f(array.sequence(path))
27
28
  }
28
29
 
29
30
  /** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
@@ -60,16 +61,16 @@ const arrayList = list('[')(']')
60
61
  /** @type {(object: Object) => seq.Sequence<string>} */
61
62
  const objectStringify = object => {
62
63
  const _0 = Object.entries(object)
63
- const _1 = seq.fromArray(_0)
64
+ const _1 = array.sequence(_0)
64
65
  const _2 = map.fromEntries(_1)
65
66
  const _3 = _2.entries
66
67
  const _4 = seq.map(property)(_3)
67
68
  return objectList(_4)
68
69
  }
69
70
 
70
- /** @type {(array: Array) => seq.Sequence<string>} */
71
- const arrayStringify = array => {
72
- const _0 = seq.fromArray(array)
71
+ /** @type {(input: Array) => seq.Sequence<string>} */
72
+ const arrayStringify = input => {
73
+ const _0 = array.sequence(input)
73
74
  const _1 = seq.map(stringSequence)(_0)
74
75
  return arrayList(_1)
75
76
  }
package/map/index.js CHANGED
@@ -43,9 +43,9 @@ const keyCmp = a => ([b]) => cmp(a)(b)
43
43
  const create = root => ({
44
44
  get: name => option.map(([,value]) => value)(getVisitor(keyCmp(name))(root)),
45
45
  set: name => value => {
46
- const result = setVisitor(keyCmp(name))(() => [name, value])(root)
47
- if ('replace' in result) { return create(result.replace) }
48
- if ('overflow' in result) { return create(result.overflow) }
46
+ const _0 = setVisitor(keyCmp(name))(() => [name, value])(root)
47
+ if ('replace' in _0) { return create(_0.replace) }
48
+ if ('overflow' in _0) { return create(_0.overflow) }
49
49
  throw ''
50
50
  },
51
51
  entries: values(root),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.194",
3
+ "version": "0.0.197",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,5 @@
1
1
  const option = require('../../option')
2
+ const seq = require('..')
2
3
 
3
4
  /**
4
5
  * @template T
@@ -94,6 +95,18 @@ const splitLast = a => {
94
95
  /** @type {(index: number) => <T>(a: Array<T>) => readonly[T]|undefined} */
95
96
  const at = index => a => index < a.length ? [a[index]] : undefined
96
97
 
98
+ /** @type {<T>(array: Array<T>) => seq.Sequence<T>} */
99
+ const sequence = a => {
100
+ /** @typedef {typeof a extends Array<infer T> ? T : never} T */
101
+ /** @type {(index: number) => seq.Sequence<T>} */
102
+ const seq = index => () => {
103
+ const result = at(index)(a)
104
+ if (result === undefined) { return undefined }
105
+ return [result[0], seq(index + 1)]
106
+ }
107
+ return seq(0)
108
+ }
109
+
97
110
  module.exports = {
98
111
  /** @readonly */
99
112
  at,
@@ -109,4 +122,6 @@ module.exports = {
109
122
  splitFirst,
110
123
  /** @readonly */
111
124
  splitLast,
125
+ /** @readonly */
126
+ sequence,
112
127
  }
package/sequence/index.js CHANGED
@@ -1,4 +1,3 @@
1
- const array = require('./array')
2
1
  const seqOp = require('./operator')
3
2
  const { combine } = require('../function')
4
3
  const op = require('../function/operator')
@@ -33,7 +32,7 @@ const { logicalNot, strictEqual } = require('../function/operator')
33
32
 
34
33
  /**
35
34
  * @template T
36
- * @typedef {array.Tuple2<T, Sequence<T>>} FirstAndTail
35
+ * @typedef {readonly[T, Sequence<T>]} FirstAndTail
37
36
  */
38
37
 
39
38
  const empty = () => undefined
@@ -93,18 +92,6 @@ const list = (...array) => {
93
92
  }
94
93
  }
95
94
 
96
- /** @type {<T>(array: array.Array<T>) => Sequence<T>} */
97
- const fromArray = a => {
98
- /** @typedef {typeof a extends array.Array<infer T> ? T : never} T */
99
- /** @type {(index: number) => Sequence<T>} */
100
- const at = index => () => {
101
- const result = array.at(index)(a)
102
- if (result === undefined) { return undefined }
103
- return [result[0], at(index + 1)]
104
- }
105
- return at(0)
106
- }
107
-
108
95
  /** @type {<T>(...array: readonly Sequence<T>[]) => Sequence<T>} */
109
96
  const concat = (...array) => {
110
97
  let i = array.length
@@ -265,7 +252,7 @@ const asyncIterable = list => ({
265
252
  }
266
253
  })
267
254
 
268
- /** @type {<A>(a: Sequence<A>) => <B>(b: Sequence<B>) => Sequence<array.Tuple2<A, B>>} */
255
+ /** @type {<A>(a: Sequence<A>) => <B>(b: Sequence<B>) => Sequence<readonly[A, B]>} */
269
256
  const zip = a => b => () => {
270
257
  const resultA = next(a)
271
258
  if (resultA === undefined) { return undefined }
@@ -293,8 +280,6 @@ module.exports = {
293
280
  /** @readonly */
294
281
  first,
295
282
  /** @readonly */
296
- fromArray,
297
- /** @readonly */
298
283
  toArray,
299
284
  /** @readonly */
300
285
  iterable,
@@ -1,3 +1,4 @@
1
+ const { iterable } = require('..')
1
2
  const { combine } = require('../../function')
2
3
  const seq = require('../operator')
3
4
 
package/sequence/test.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const seq = require('.')
2
2
  const { sum } = require('./operator')
3
3
  const op = require('./operator')
4
+ const array = require('./array')
4
5
 
5
6
  /** @type {<T>(input: seq.Sequence<T>) => void} */
6
7
  const print = input => {
@@ -14,9 +15,9 @@ const print = input => {
14
15
  }
15
16
 
16
17
  {
17
- const big = seq.fromArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 42, 60])
18
- const list0 = seq.fromArray([0, 1, 2, 3])
19
- const list1 = seq.flatMap(x => seq.fromArray([x, x * 2, x * 3]))(list0)
18
+ const big = seq.list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 42, 60)
19
+ const list0 = seq.list(0, 1, 2, 3)
20
+ const list1 = seq.flatMap(x => seq.list(x, x * 2, x * 3))(list0)
20
21
  const list2 = seq.concat(list0, list0)
21
22
  const list3 = seq.exclusiveScan(sum)(list0)
22
23
  const r = seq.find(x => x === 42)(big)
@@ -27,7 +28,7 @@ const print = input => {
27
28
  if (seq.first(seq.drop(16)(big)) !== 42) { throw 'drop'}
28
29
  {
29
30
  const a = seq.toArray(seq.generate(1_000_000))
30
- let x = seq.concat(seq.fromArray(a), big)
31
+ let x = seq.concat(array.sequence(a), big)
31
32
  const r = seq.next(x)
32
33
  // print(x)
33
34
  }
@@ -57,6 +58,6 @@ const print = input => {
57
58
  }
58
59
 
59
60
  {
60
- const x = seq.join(':')(seq.fromArray(["1", "2", "3", "4", "5", "6"]))
61
+ const x = seq.join(':')(seq.list("1", "2", "3", "4", "5", "6"))
61
62
  if (x !== "1:2:3:4:5:6") { throw x }
62
63
  }