functionalscript 0.0.313 → 0.0.314

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.
@@ -20,8 +20,8 @@ const split = path => path.split('/')
20
20
 
21
21
  /** @typedef {readonly[list.List<string>] | undefined} OptionList */
22
22
 
23
- /** @type {(s: OptionList) => (items: string) => OptionList} */
24
- const normItemsOp = prior => first => {
23
+ /** @type {(items: string) => (prior: OptionList) => OptionList} */
24
+ const normItemsOp = first => prior => {
25
25
  if (prior === undefined) { return undefined }
26
26
  const tail = prior[0]
27
27
  switch (first) {
package/json/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  const seq = require('../types/list')
2
2
  const object = require('../types/object')
3
- const array = require('../types/array')
4
3
  const op = require('../types/function/operator')
4
+ const { compose } = require('../types/function')
5
5
 
6
- /**
6
+ /**
7
7
  * @typedef {{
8
8
  * readonly [k in string]: Unknown
9
- * }} Object
9
+ * }} Object
10
10
  */
11
11
 
12
12
  /** @typedef {readonly Unknown[]} Array */
@@ -22,7 +22,7 @@ const setProperty = value => {
22
22
  const srcObject = (src === undefined || src === null || typeof src !== 'object' || src instanceof Array) ? {} : src
23
23
  const { first, tail } = result
24
24
  return { ...srcObject, [first]: f(tail)(object.at(first)(srcObject)) }
25
- }
25
+ }
26
26
  return f
27
27
  }
28
28
 
@@ -45,7 +45,7 @@ const colon = [':']
45
45
  const comma = [',']
46
46
 
47
47
  /** @type {op.Fold<seq.List<string>>} */
48
- const joinOp = a => b => seq.flat([a, comma, b])
48
+ const joinOp = b => prior => seq.flat([prior, comma, b])
49
49
 
50
50
  /** @type {(input: seq.List<seq.List<string>>) => seq.List<string>} */
51
51
  const join = seq.fold(joinOp)([])
@@ -76,19 +76,8 @@ const serialize = sort => {
76
76
  f(v)
77
77
  ])
78
78
  /** @type {(object: Object) => seq.List<string>} */
79
- const objectSerialize = input => {
80
- const entries = Object.entries(input)
81
- const sortedEntries = sort(entries)
82
- const _ = seq.toArray(sortedEntries)
83
- const serializedEntries = seq.map(propertySerialize)(sortedEntries)
84
- return objectList(serializedEntries)
85
- }
86
- /** @type {(input: Array) => seq.List<string>} */
87
- const arraySerialize = input => {
88
- const serializedEntries = seq.map(f)(input)
89
- return arrayList(serializedEntries)
90
- }
91
- /** @type {(value: Unknown) => seq.List < string >} */
79
+ const objectSerialize = input => objectList(seq.map(propertySerialize)(sort(Object.entries(input))))
80
+ /** @type {(value: Unknown) => seq.List<string>} */
92
81
  const f = value => {
93
82
  switch (typeof value) {
94
83
  case 'boolean': { return boolSerialize(value) }
@@ -101,22 +90,21 @@ const serialize = sort => {
101
90
  }
102
91
  }
103
92
  }
93
+ /** @type {(input: Array) => seq.List<string>} */
94
+ const arraySerialize = compose(seq.map(f))(arrayList)
104
95
  return f
105
96
  }
106
97
 
107
98
  /**
108
- * The standard `JSON.stringify` rules determined by
99
+ * The standard `JSON.stringify` rules determined by
109
100
  * https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
110
- *
101
+ *
111
102
  * @type {(mapEntries: MapEntries) => (value: Unknown) => string}
112
103
  */
113
- const stringify = sort => value => {
114
- const _s = serialize(sort)(value)
115
- return seq.join('')(_s)
116
- }
104
+ const stringify = sort => compose(serialize(sort))(seq.join(''))
117
105
 
118
106
  /** @type {(value: string) => Unknown} */
119
- const parse = value => JSON.parse(value)
107
+ const parse = JSON.parse
120
108
 
121
109
  /** @type {(value: Unknown) => value is Object} */
122
110
  const isObject = value => typeof value === 'object' && value !== null && !(value instanceof Array)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.313",
3
+ "version": "0.0.314",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -92,8 +92,8 @@ const initValue1 = a => n => {
92
92
  * @typedef {(a: A) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} Merge
93
93
  */
94
94
 
95
- /** @type {<A, T>(ms: array.Array2<Merge<A, T>>) => (a: A) => (i: find.PathItem<T>) => Branch<T>} */
96
- const reduceX = ms => a => i => {
95
+ /** @type {<A, T>(ms: array.Array2<Merge<A, T>>) => (i: find.PathItem<T>) => (a: A) => Branch<T>} */
96
+ const reduceX = ms => i => a => {
97
97
  const [m0, m2] = ms
98
98
  /** @typedef {typeof ms extends array.Array2<Merge<infer A, infer T>> ? [A,T] : never} AT */
99
99
  /** @typedef {AT[0]} A */
@@ -155,7 +155,7 @@ const nodeRemove = c => node => {
155
155
  const tailR = list.next(tail)
156
156
  if (tailR === undefined) { return first }
157
157
  const { first: tf, tail: tt } = tailR
158
- const result = reduce(initReduce(first)(tf))(tt)
158
+ const result = reduce(initReduce(tf)(first))(tt)
159
159
  return result.length === 1 ? result[0] : result
160
160
  }
161
161
 
@@ -11,8 +11,8 @@ const list = require('../../list')
11
11
  /** @type {<T>(b: _.Branch5<T> | _.Branch7<T>) => Bracnh1To3<T>} */
12
12
  const b57 = b => b.length === 5 ? [b] : [[b[0], b[1], b[2]], b[3], [b[4], b[5], b[6]]]
13
13
 
14
- /** @type {<T>(a: Bracnh1To3<T>) => (i: find.PathItem<T>) => Bracnh1To3<T>} */
15
- const reduce = a => i => {
14
+ /** @type {<T>(i: find.PathItem<T>) => (a: Bracnh1To3<T>) => Bracnh1To3<T>} */
15
+ const reduce = i => a => {
16
16
  switch (i[0]) {
17
17
  case 0: {
18
18
  const x = i[1]
@@ -7,18 +7,20 @@
7
7
 
8
8
  /**
9
9
  * @template I,O
10
- * @typedef {Binary<O, I, O>} Reduce
10
+ * @typedef {Binary<I, O, O>} Reduce
11
11
  */
12
12
 
13
13
  /** @type {(separator: string) => Fold<string>} */
14
- const join = separator => prior => value => `${prior}${separator}${value}`
14
+ const join = separator => value => prior => `${prior}${separator}${value}`
15
15
 
16
16
  /** @type {Fold<string>} */
17
- const concat = a => b => `${a}${b}`
17
+ const concat = i => acc => `${acc}${i}`
18
18
 
19
19
  /** @type {Fold<number>} */
20
20
  const addition = a => b => a + b
21
21
 
22
+ const increment = addition(1)
23
+
22
24
  /**
23
25
  * @template T
24
26
  * @template R
@@ -60,7 +62,7 @@ const stateScanToScan = op => prior => i => {
60
62
 
61
63
  /** @type {<I, O>(reduce: Reduce<I, O>) => (prior: O) => Scan<I, O>} */
62
64
  const reduceToScan = reduce => prior => i => {
63
- const result = reduce(prior)(i)
65
+ const result = reduce(i)(prior)
64
66
  return [result, reduceToScan(reduce)(result)]
65
67
  }
66
68
 
@@ -72,8 +74,7 @@ const reduceToScan = reduce => prior => i => {
72
74
  /** @type {<T>(fold: Fold<T>) => Scan<T, T>} */
73
75
  const foldToScan = op => init => [init, reduceToScan(op)(init)]
74
76
 
75
- /** @type {(a: number) => () => number} */
76
- const counter = a => () => a + 1
77
+ const counter = () => increment
77
78
 
78
79
  module.exports = {
79
80
  /** @readonly */
@@ -81,6 +82,8 @@ module.exports = {
81
82
  /** @readonly */
82
83
  addition,
83
84
  /** @readonly */
85
+ increment,
86
+ /** @readonly */
84
87
  strictEqual,
85
88
  /** @readonly */
86
89
  logicalNot,
@@ -268,8 +268,8 @@ const entries = input => {
268
268
  return stateScan(/** @type {operator.StateScan<T, Number, Entry<T>>} */(entryOperator))(0)(input)
269
269
  }
270
270
 
271
- /** @type {<T>(prior: List<T>) => (value: T) => List<T>} */
272
- const reverseOperator = tail => first => ({ first, tail })
271
+ /** @type {<T>(value: T) => (prior: List<T>) => List<T>} */
272
+ const reverseOperator = first => tail => ({ first, tail })
273
273
 
274
274
  /** @type {<T>(input: List<T>) => List<T>} */
275
275
  const reverse = reduce(reverseOperator)(undefined)
@@ -6,7 +6,6 @@ const compare = require('../function/compare')
6
6
  const { stringCmp } = require('../function/compare')
7
7
  const list = require('../list')
8
8
  const btRemove = require('../btree/remove')
9
- const { flip } = require('../function')
10
9
 
11
10
  /** @typedef {compare.Sign} Sign */
12
11
 
@@ -45,7 +44,7 @@ const set = name => value => setEntry([name, value])
45
44
  const entries = values
46
45
 
47
46
  /** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
48
- const fromEntries = list.reduce(flip(setEntry))(undefined)
47
+ const fromEntries = list.reduce(setEntry)(undefined)
49
48
 
50
49
  /** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
51
50
  const remove = name => btRemove.remove(keyCmp(name))
@@ -19,8 +19,11 @@ const at = name => object => Object.getOwnPropertyDescriptor(object, name)?.valu
19
19
  /** @type {<T>(entries: list.List<Entry<T>>) => list.List<Entry<T>>} */
20
20
  const sort = entries => map.entries(map.fromEntries(entries))
21
21
 
22
+ /** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
23
+ const fromEntries = entries => Object.fromEntries(list.iterable(entries))
24
+
22
25
  /** @type {<T>(m: map.Map<T>) => Map<T>} */
23
- const fromMap = m => Object.fromEntries(list.iterable(map.entries(m)))
26
+ const fromMap = m => fromEntries(map.entries(m))
24
27
 
25
28
  module.exports = {
26
29
  /** @readonly */
@@ -28,5 +31,7 @@ module.exports = {
28
31
  /** @readonly */
29
32
  sort,
30
33
  /** @readonly */
34
+ fromEntries,
35
+ /** @readonly */
31
36
  fromMap,
32
37
  }
@@ -4,7 +4,7 @@ const btSet = require('../btree/set')
4
4
  const btRemove = require('../btree/remove')
5
5
  const { stringCmp } = require("../function/compare")
6
6
  const list = require('../list')
7
- const { flip, compose } = require('../function')
7
+ const { compose } = require('../function')
8
8
 
9
9
  /** @typedef {btree.Tree<string>} StringSet */
10
10
 
@@ -17,7 +17,7 @@ const set = value => btSet.set(stringCmp(value))(value)
17
17
  /** @type {(s: StringSet) => list.List<string>} */
18
18
  const values = btree.values
19
19
 
20
- const fromValues = list.reduce(flip(set))(undefined)
20
+ const fromValues = list.reduce(set)(undefined)
21
21
 
22
22
  /** @type {(value: string) => (s: StringSet) => StringSet} */
23
23
  const remove = compose(stringCmp)(btRemove.remove)