functionalscript 0.0.174 → 0.0.176
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 +1 -1
- package/sequence/list/index.js +14 -9
- package/sequence/list/test.js +3 -2
package/package.json
CHANGED
package/sequence/list/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const array = require('../array')
|
|
|
2
2
|
const option = require('../../option')
|
|
3
3
|
const base = require('..')
|
|
4
4
|
const { pipe } = require('../../function')
|
|
5
|
+
const { todo } = require('../../dev')
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @template T
|
|
@@ -53,15 +54,19 @@ const concat = a => b => () => {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/** @type {<T, R>(f: (value: T) => List<R>) => ListMap<T, R>} */
|
|
56
|
-
const flatMap = f => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
const flatMap = f => input => () => {
|
|
58
|
+
let i = input
|
|
59
|
+
while (true) {
|
|
60
|
+
const result = i()
|
|
61
|
+
if (result === undefined) { return undefined }
|
|
62
|
+
const [first, tail] = result
|
|
63
|
+
const firstResult = f(first)()
|
|
64
|
+
if (firstResult !== undefined) {
|
|
65
|
+
const [firstFirst, firstTail] = firstResult
|
|
66
|
+
return [firstFirst, concat(firstTail)(flatMap(f)(tail))]
|
|
67
|
+
}
|
|
68
|
+
i = tail
|
|
69
|
+
}
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
/** @type {<T>(list: List<List<T>>) => List<T>} */
|
package/sequence/list/test.js
CHANGED
|
@@ -12,13 +12,14 @@ const print = a => {
|
|
|
12
12
|
|
|
13
13
|
{
|
|
14
14
|
const big = list.fromArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 42, 60])
|
|
15
|
-
print(big)
|
|
15
|
+
// print(big)
|
|
16
16
|
/*
|
|
17
17
|
const list0 = list.fromArray([0, 1, 2, 3])
|
|
18
18
|
const list1 = list.flatMap(x => list.fromArray([x, x * 2, x * 3]))(list0)
|
|
19
19
|
const list2 = list.concat(list0)(list0)
|
|
20
20
|
const list3 = list.inclusiveScan(sum)(list0)
|
|
21
21
|
print(list3)
|
|
22
|
-
const r = list.find(x => x === 42)(list.fromArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 42, 60]))
|
|
23
22
|
*/
|
|
23
|
+
const r = list.find(x => x === 42)(big)
|
|
24
|
+
console.log(r)
|
|
24
25
|
}
|