const takeAll = take(Infinity);
L.map = curry(function *(f, iter) {
for (const a of iter) {
yield f(a);
}
});
const map = curry(pipe(L.map, takeAll));
log(map(a => a + 10, L.range(4)));
L.filter + take๋ก filter ๋ง๋ค๊ธฐ
L.filter = curry(fuction *(f, iter) {
for (const a of iter ) {
if (f(a)) yield a;
}
});
const filter = curry(pipe(L.filter, takeAll));
log(filter(a => a % 2, range(4)));
L.flatten
// ๋ฐ๋ก ํ๊ฐ๋๋ flatten ํจ์
const flatten = pipe(L.flatten, takeAll);
const isIterable = a => a && a[Symbol.iterator];
// ๊น์ Iterable์ ๋ชจ๋ ํผ์น ๋
L.deepFlat = function*(iter) {
for (const a of iter) {
if (isIterable(a)) yield *f(a);
else yield a;
}
}
L.flatten = function *(iter) {
for (const a of iter) {
if (isIterable(a)) yield *a;
// if (isIterable(a)) for (const b of a) yield b;
// yield *iterabel = for (const val of iterable) yield val;
else yield a;
}
var it = L.flatten([[1,2], 3, 4, [5, 6], [7, 8, 9]]);
log([...it]);
};