-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk-chain.spl.js
47 lines (37 loc) · 1.07 KB
/
chunk-chain.spl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const GF = require('../index');
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
console.log('orginal array', x)
console.log('chunk fixed size', x.chunk(3));
console.log('chunk array of sizes', x.chunk([1, 2]));
function* finite() {
yield 1;
yield 3;
yield 2;
}
console.log('chunk finite generator', x.chunk(finite()));
function* infinite() {
while (true) {
yield 2;
yield 3;
}
}
function* random(M) {
while (M-- > 0)
yield Math.round(Math.random() * 10) + 1;
}
console.log('chunk infinite-loop generator', x.chunk(infinite()))
const a = [1, 2]
const b = [3, 4, 5]
const c = [6, 7]
const d = [8, 9, 10]
console.log('chain arrays', Array.chain(a, b, c, d))
console.log('chain mixed arrays and generators', Array.chain(a, finite(), b, random(10)));
// [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10 ] ]
// // console.log('chain',Array.chain(...x.chunk([1, 2])));
// function* s() {
// for (let i = 1; ; i++) yield i;
// }
// random = s().imap(i=>Math.round(Math.random()*10)+1)
// for (let c of s().ichunk(random)) {
// console.log(c);
// }