This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function forEach(op) { | |
return async function (src) { | |
let index = 0; | |
for await (const value of src) { | |
if (op(value, index++) === false) { | |
break; | |
} | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function forEach(src, op) { | |
let index = 0; | |
for await (const value of src) { | |
if (op(value, index++) === false) { | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filter(op) { | |
return function* (src) { | |
for (const value of src) { | |
if (op(value)) { | |
yield value; | |
} | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* filter(src, op) { | |
for (const value of src) { | |
if (op(value)) { | |
yield value; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const result = pipe( | |
numbers, | |
filter(v => v % 2 == 0), | |
map(v => v + 1), | |
slice(0, 3), | |
Array.from | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe(arg, ...fns) { | |
return fns.reduce((v, fn) => fn(v), arg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const result = numbers | |
|> filter(#, v => v % 2 === 0) | |
|> map(#, v => v + 1) | |
|> slice(#, 0, 3) | |
|> Array.from; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const result = Array.from(slice(map(filter(numbers, v => v % 2 === 0), v => v + 1), 0, 3)); |
NewerOlder