functionalscript 0.0.208 → 0.0.214
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 +9 -10
- package/map/index.js +0 -1
- package/module-manager/index.js +2 -2
- package/package.json +1 -1
- package/sequence/asyncIterable/index.js +2 -2
- package/sequence/index.js +19 -2
- package/sequence/iterable/index.js +2 -3
- package/sequence/iterable/test.js +2 -2
- package/sequence/test.js +9 -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,9 +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')
|
|
6
|
-
const {
|
|
5
|
+
const { compose } = require('../function')
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @typedef {{
|
|
@@ -25,7 +24,7 @@ const addProperty = value => {
|
|
|
25
24
|
const [name, tail] = result
|
|
26
25
|
return { ...srcObject, [name]: f(tail)(object.at(name)(srcObject)) }
|
|
27
26
|
}
|
|
28
|
-
return
|
|
27
|
+
return compose(f)(array.sequence)
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
/** @type {(_: string) => seq.Sequence<string>} */
|
|
@@ -84,16 +83,16 @@ const serialize = sort => {
|
|
|
84
83
|
f(v))
|
|
85
84
|
/** @type {(object: Object) => seq.Sequence<string>} */
|
|
86
85
|
const objectSerialize = input => {
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
return objectList(
|
|
86
|
+
const entries = object.entries(input)
|
|
87
|
+
const sortedEntries = sort(entries)
|
|
88
|
+
const serializedEntries = seq.map(propertySerialize)(sortedEntries)
|
|
89
|
+
return objectList(serializedEntries)
|
|
91
90
|
}
|
|
92
91
|
/** @type {(input: Array) => seq.Sequence<string>} */
|
|
93
92
|
const arraySerialize = input => {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
return arrayList(
|
|
93
|
+
const sequence = array.sequence(input)
|
|
94
|
+
const serializedEntries = seq.map(f)(sequence)
|
|
95
|
+
return arrayList(serializedEntries)
|
|
97
96
|
}
|
|
98
97
|
/** @type {(value: Json) => seq.Sequence < string >} */
|
|
99
98
|
const f = value => {
|
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/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 => ({
|
|
@@ -265,6 +265,21 @@ const zip = a => b => () => {
|
|
|
265
265
|
return [[resultA[0], resultB[0]], zip(resultA[1])(resultB[1])]
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/** @type {<T>(s: Sequence<T>) => Sequence<T>} */
|
|
269
|
+
const reverse = s => {
|
|
270
|
+
/** @type {typeof s} */
|
|
271
|
+
let iResult = empty
|
|
272
|
+
let iSource = s
|
|
273
|
+
while (true) {
|
|
274
|
+
const result = next(iSource)
|
|
275
|
+
if (result === undefined) { return iResult }
|
|
276
|
+
/** @type {typeof s} */
|
|
277
|
+
const old = iResult
|
|
278
|
+
iResult = () => [result[0], old]
|
|
279
|
+
iSource = result[1]
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
268
283
|
module.exports = {
|
|
269
284
|
/** @readonly */
|
|
270
285
|
next,
|
|
@@ -326,4 +341,6 @@ module.exports = {
|
|
|
326
341
|
includes,
|
|
327
342
|
/** @readonly */
|
|
328
343
|
zip,
|
|
344
|
+
/** @readonly */
|
|
345
|
+
reverse,
|
|
329
346
|
}
|
|
@@ -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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const seq = require('.')
|
|
2
2
|
const { sum } = require('./operator')
|
|
3
|
-
const op = require('./operator')
|
|
4
3
|
const array = require('./array')
|
|
4
|
+
const json = require('../json')
|
|
5
|
+
const { id } = require('../function')
|
|
5
6
|
|
|
6
7
|
/** @type {<T>(input: seq.Sequence<T>) => void} */
|
|
7
8
|
const print = input => {
|
|
@@ -64,3 +65,10 @@ const print = input => {
|
|
|
64
65
|
const x = seq.join(':')(seq.list("1", "2", "3", "4", "5", "6"))
|
|
65
66
|
if (x !== "1:2:3:4:5:6") { throw x }
|
|
66
67
|
}
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
const r = seq.reverse(seq.list(1, 2, 3, 4))
|
|
71
|
+
const s = array.fromSequence(r)
|
|
72
|
+
const j = json.stringify(id)(s)
|
|
73
|
+
if (j !== '[4,3,2,1]') { throw j }
|
|
74
|
+
}
|