partitionMap
import { partitionMap } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/async_iterable.ts";Partition and map an AsyncIterable based on an Either-returning function.
@example
import { partitionMap } from "./async_iterable.ts";
import { fromIterable } from "./async_iterable.ts";
import * as E from "./either.ts";
import { pipe } from "./fn.ts";
const strings = fromIterable(["1", "2", "abc", "3", "def"]);
const [numbers, errors] = pipe(
strings,
partitionMap(str => {
const num = parseInt(str);
return isNaN(num) ? E.left(str) : E.right(num);
})
);
for await (const value of numbers) {
console.log(`Number: ${value}`); // Number: 1, Number: 2, Number: 3
}
for await (const value of errors) {
console.log(`Error: ${value}`); // Error: abc, Error: def
}