functionalscript 0.0.205 → 0.0.212
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/.github/FUNDING.yml +12 -0
- package/function/index.js +2 -2
- package/json/index.js +43 -36
- package/json/test.js +22 -3
- package/map/index.js +0 -1
- package/module-manager/index.js +2 -2
- package/object/index.js +18 -2
- package/object/test.js +13 -0
- package/package.json +1 -1
- package/sequence/asyncIterable/index.js +2 -2
- package/sequence/index.js +2 -2
- package/sequence/iterable/index.js +2 -3
- package/sequence/iterable/test.js +2 -2
- package/sequence/test.js +0 -1
- package/test.js +8 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# These are supported funding model platforms
|
|
2
|
+
|
|
3
|
+
github: [sergey-shandar] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
+
patreon: # Replace with a single Patreon username
|
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
+
otechie: # Replace with a single Otechie username
|
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
package/function/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/** @type {<X, O>(f: Func<X, O>) => <I>(g: Func<I, X>) => Func<I, O>} */
|
|
8
|
-
const
|
|
8
|
+
const compose = f => g => x => f(g(x))
|
|
9
9
|
|
|
10
10
|
/** @type {<T>(value: T) => T} */
|
|
11
11
|
const id = value => value
|
|
@@ -14,5 +14,5 @@ module.exports = {
|
|
|
14
14
|
/** @readonly */
|
|
15
15
|
id,
|
|
16
16
|
/** @readonly */
|
|
17
|
-
|
|
17
|
+
compose,
|
|
18
18
|
}
|
package/json/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const seq = require('../sequence')
|
|
2
|
-
const map = require('../map')
|
|
3
2
|
const op = require('../sequence/operator')
|
|
4
3
|
const object = require('../object')
|
|
5
4
|
const array = require('../sequence/array')
|
|
5
|
+
const { compose } = require('../function')
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {{
|
|
@@ -22,9 +22,9 @@ const addProperty = value => {
|
|
|
22
22
|
if (result === undefined) { return value }
|
|
23
23
|
const srcObject = (src === undefined || src === null || typeof src !== 'object' || src instanceof Array) ? {} : src
|
|
24
24
|
const [name, tail] = result
|
|
25
|
-
return { ...srcObject, [name]: f(tail)(
|
|
25
|
+
return { ...srcObject, [name]: f(tail)(object.at(name)(srcObject)) }
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return compose(f)(array.sequence)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** @type {(_: string) => seq.Sequence<string>} */
|
|
@@ -42,12 +42,6 @@ const falseSerialize = seq.list('false')
|
|
|
42
42
|
/** @type {(_: boolean) => seq.Sequence<string>} */
|
|
43
43
|
const boolSerialize = value => value ? trueSerialize : falseSerialize
|
|
44
44
|
|
|
45
|
-
/** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
|
|
46
|
-
const propertySerialize = ([k, v]) => seq.concat(
|
|
47
|
-
stringSerialize(k),
|
|
48
|
-
colon,
|
|
49
|
-
serialize(v))
|
|
50
|
-
|
|
51
45
|
const colon = seq.list(':')
|
|
52
46
|
const comma = seq.list(',')
|
|
53
47
|
|
|
@@ -74,33 +68,46 @@ const objectList = list('{')('}')
|
|
|
74
68
|
|
|
75
69
|
const arrayList = list('[')(']')
|
|
76
70
|
|
|
77
|
-
/** @
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** @type {(
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
71
|
+
/** @typedef {object.Entry<Json>} Entry*/
|
|
72
|
+
|
|
73
|
+
/** @typedef {(seq.Sequence<Entry>)} Entries */
|
|
74
|
+
|
|
75
|
+
/** @typedef {(entries: Entries) => Entries} MapEntries */
|
|
76
|
+
|
|
77
|
+
/** @type {(mapEntries: MapEntries) => (value: Json) => seq.Sequence<string>} */
|
|
78
|
+
const serialize = sort => {
|
|
79
|
+
/** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
|
|
80
|
+
const propertySerialize = ([k, v]) => seq.concat(
|
|
81
|
+
stringSerialize(k),
|
|
82
|
+
colon,
|
|
83
|
+
f(v))
|
|
84
|
+
/** @type {(object: Object) => seq.Sequence<string>} */
|
|
85
|
+
const objectSerialize = input => {
|
|
86
|
+
const entries = object.entries(input)
|
|
87
|
+
const sortedEntries = sort(entries)
|
|
88
|
+
const serializedEntries = seq.map(propertySerialize)(sortedEntries)
|
|
89
|
+
return objectList(serializedEntries)
|
|
90
|
+
}
|
|
91
|
+
/** @type {(input: Array) => seq.Sequence<string>} */
|
|
92
|
+
const arraySerialize = input => {
|
|
93
|
+
const sequence = array.sequence(input)
|
|
94
|
+
const serializedEntries = seq.map(f)(sequence)
|
|
95
|
+
return arrayList(serializedEntries)
|
|
96
|
+
}
|
|
97
|
+
/** @type {(value: Json) => seq.Sequence < string >} */
|
|
98
|
+
const f = value => {
|
|
99
|
+
switch (typeof value) {
|
|
100
|
+
case 'boolean': { return boolSerialize(value) }
|
|
101
|
+
case 'number': { return numberSerialize(value) }
|
|
102
|
+
case 'string': { return stringSerialize(value) }
|
|
103
|
+
default: {
|
|
104
|
+
if (value === null) { return nullSerialize }
|
|
105
|
+
if (value instanceof Array) { return arraySerialize(value) }
|
|
106
|
+
return objectSerialize(value)
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
}
|
|
110
|
+
return f
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
/**
|
|
@@ -109,9 +116,9 @@ const serialize = value => {
|
|
|
109
116
|
* The standard `JSON.stringify` rules determines by
|
|
110
117
|
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
111
118
|
*
|
|
112
|
-
* @type {(value: Json) => string}
|
|
119
|
+
* @type {(mapEntries: MapEntries) => (value: Json) => string}
|
|
113
120
|
*/
|
|
114
|
-
const stringify = value => seq.join('')(serialize(value))
|
|
121
|
+
const stringify = sort => value => seq.join('')(serialize(sort)(value))
|
|
115
122
|
|
|
116
123
|
/** @type {(value: string) => Json} */
|
|
117
124
|
const parse = value => JSON.parse(value)
|
package/json/test.js
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
const json = require('.')
|
|
2
|
+
const { sort } = require('../object')
|
|
3
|
+
const { id } = require('../function')
|
|
2
4
|
|
|
3
5
|
if (json.addProperty("Hello")([])({}) !== "Hello") { throw 'error' }
|
|
4
6
|
|
|
5
7
|
{
|
|
6
|
-
const x = json.stringify(json.addProperty("Hello")(['a'])({}))
|
|
8
|
+
const x = json.stringify(sort)(json.addProperty("Hello")(['a'])({}))
|
|
7
9
|
if (x !== '{"a":"Hello"}') { throw x }
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
{
|
|
11
|
-
const x = json.stringify(json.addProperty("Hello")(['a'])({
|
|
13
|
+
const x = json.stringify(id)(json.addProperty("Hello")(['a'])({}))
|
|
14
|
+
if (x !== '{"a":"Hello"}') { throw x }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
const x = json.stringify(sort)(json.addProperty("Hello")(['a'])({c:[],b:12}))
|
|
12
19
|
if (x !== '{"a":"Hello","b":12,"c":[]}') { throw x }
|
|
13
20
|
}
|
|
14
21
|
|
|
22
|
+
{
|
|
23
|
+
const x = json.stringify(id)(json.addProperty("Hello")(['a'])({ c: [], b: 12 }))
|
|
24
|
+
if (x !== '{"c":[],"b":12,"a":"Hello"}') { throw x }
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
{
|
|
16
28
|
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
17
29
|
const _1 = json.addProperty("Hello")(['a', 'x'])(_0)
|
|
18
|
-
const _2 = json.stringify(_1)
|
|
30
|
+
const _2 = json.stringify(sort)(_1)
|
|
19
31
|
if (_2 !== '{"a":{"x":"Hello","y":[24]},"b":12,"c":[]}') { throw _2 }
|
|
20
32
|
}
|
|
33
|
+
|
|
34
|
+
{
|
|
35
|
+
const _0 = { a: { y: [24] }, c: [], b: 12 }
|
|
36
|
+
const _1 = json.addProperty("Hello")(['a', 'x'])(_0)
|
|
37
|
+
const _2 = json.stringify(id)(_1)
|
|
38
|
+
if (_2 !== '{"a":{"y":[24],"x":"Hello"},"c":[],"b":12}') { throw _2 }
|
|
39
|
+
}
|
package/map/index.js
CHANGED
package/module-manager/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const array = require('../sequence/array')
|
|
2
|
-
const {
|
|
2
|
+
const { compose } = require('../function')
|
|
3
3
|
const option = require('../option')
|
|
4
4
|
const { head, last, splitLast, splitFirst } = array
|
|
5
5
|
const iter = require('../sequence/iterable')
|
|
@@ -88,7 +88,7 @@ const external = packages => {
|
|
|
88
88
|
const defined = ([first, tail]) => externalOrInternal(packages(first))(tail)
|
|
89
89
|
/** @type {(_: Path) => readonly [string, Path]|undefined} */
|
|
90
90
|
const sf = splitFirst
|
|
91
|
-
return
|
|
91
|
+
return compose
|
|
92
92
|
(option.map(defined))
|
|
93
93
|
(sf)
|
|
94
94
|
}
|
package/object/index.js
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
const array = require('../sequence/array')
|
|
2
2
|
const seq = require('../sequence')
|
|
3
|
+
const map = require('../map')
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @template T
|
|
6
7
|
* @typedef {{
|
|
7
8
|
* readonly [k in string]: T
|
|
8
|
-
* }}
|
|
9
|
+
* }} Map
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* @template T
|
|
14
|
+
* @typedef {readonly[string, T]} Entry
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @type {<T>(object: Map<T>) => seq.Sequence<Entry<T>>} */
|
|
12
18
|
const entries = object => array.sequence(Object.entries(object))
|
|
13
19
|
|
|
20
|
+
/** @type {(name: string) => <T>(object: Map<T>) => T|undefined} */
|
|
21
|
+
const at = name => object => Object.getOwnPropertyDescriptor(object, name)?.value
|
|
22
|
+
|
|
23
|
+
/** @type {<T>(entries: seq.Sequence<Entry<T>>) => seq.Sequence<Entry<T>>} */
|
|
24
|
+
const sort = entries => map.fromEntries(entries).entries
|
|
25
|
+
|
|
14
26
|
module.exports = {
|
|
15
27
|
/** @readonly */
|
|
16
28
|
entries,
|
|
29
|
+
/** @readonly */
|
|
30
|
+
at,
|
|
31
|
+
/** @readonly */
|
|
32
|
+
sort,
|
|
17
33
|
}
|
package/object/test.js
ADDED
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { compose } = require('../../function')
|
|
2
2
|
const seq = require('../operator')
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -69,7 +69,7 @@ const reduce = ([first, s]) => async c => {
|
|
|
69
69
|
|
|
70
70
|
const sum = reduce(seq.sum)
|
|
71
71
|
|
|
72
|
-
const join =
|
|
72
|
+
const join = compose(reduce)(seq.join)
|
|
73
73
|
|
|
74
74
|
const length = reduce(seq.length)
|
|
75
75
|
|
package/sequence/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const seqOp = require('./operator')
|
|
2
|
-
const {
|
|
2
|
+
const { compose } = require('../function')
|
|
3
3
|
const op = require('../function/operator')
|
|
4
4
|
const { logicalNot, strictEqual } = require('../function/operator')
|
|
5
5
|
|
|
@@ -228,7 +228,7 @@ const some = f => input => find(x => x)(map(f)(input)) !== undefined
|
|
|
228
228
|
const includes = value => some(strictEqual(value))
|
|
229
229
|
|
|
230
230
|
/** @type {<T>(f: (value: T) => boolean) => SequenceReduce<T, boolean>} */
|
|
231
|
-
const every = f => input => !some(
|
|
231
|
+
const every = f => input => !some(compose(logicalNot)(f))(input)
|
|
232
232
|
|
|
233
233
|
/** @type {<T>(list: Sequence<T>) => Iterable<T>} */
|
|
234
234
|
const iterable = list => ({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const { combine } = require('../../function')
|
|
1
|
+
const { compose } = require('../../function')
|
|
3
2
|
const seq = require('../operator')
|
|
4
3
|
|
|
5
4
|
/** @type {<T>(a: Iterable<T>) => (b: Iterable<T>) => Iterable<T>} */
|
|
@@ -40,7 +39,7 @@ const sum = reduce(seq.sum)
|
|
|
40
39
|
|
|
41
40
|
const length = reduce(seq.length)
|
|
42
41
|
|
|
43
|
-
const join =
|
|
42
|
+
const join = compose(reduce)(seq.join)
|
|
44
43
|
|
|
45
44
|
/** @type {<T, R>(f: (value: T) => Iterable<R>) => (c: Iterable<T>) => Iterable<R>} */
|
|
46
45
|
const flatMap = f => c => ({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const i = require('.')
|
|
2
|
-
const {
|
|
2
|
+
const { compose } = require('../../function')
|
|
3
3
|
|
|
4
4
|
{
|
|
5
5
|
const r = i.sum([120, 300, 42])
|
|
@@ -33,7 +33,7 @@ const { combine } = require('../../function')
|
|
|
33
33
|
/** @type {(_: string) => string|undefined} */
|
|
34
34
|
const file = _ => 'x'
|
|
35
35
|
/** @type {(_: string) => string|undefined} */
|
|
36
|
-
const x = p =>
|
|
36
|
+
const x = p => compose
|
|
37
37
|
(i.find(x => x !== undefined))
|
|
38
38
|
(i.map(x => file(x())))
|
|
39
39
|
([() => p, () => `${p}.js`, () => `${p}/index.js`])
|
package/sequence/test.js
CHANGED
package/test.js
CHANGED
|
@@ -6,6 +6,7 @@ require('./sequence/iterable/test')
|
|
|
6
6
|
require('./sequence/asyncIterable/test')
|
|
7
7
|
require('./module-manager/test')
|
|
8
8
|
require('./json/test')
|
|
9
|
+
require('./object/test')
|
|
9
10
|
|
|
10
11
|
/** @type {() => never} */
|
|
11
12
|
const assert = () => { throw 'assert' }
|
|
@@ -104,6 +105,12 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
|
|
|
104
105
|
//const c = o['isPrototypeOf']
|
|
105
106
|
//const c = o['propertyIsEnumerable']
|
|
106
107
|
//const c = o['toString']
|
|
107
|
-
const c = o['valueOf']
|
|
108
|
+
const c = o['valueOf']
|
|
108
109
|
console.log(c)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
{
|
|
113
|
+
const x = { 'a': 12 }
|
|
114
|
+
const c = Object.getOwnPropertyDescriptor(x, 'constructor')
|
|
115
|
+
const a = Object.getOwnPropertyDescriptor(x, 'a')
|
|
109
116
|
}
|