Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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
}
function partitionMap<A, I, J>(predicate: (a: A) => Either<J, I>): (ua: AsyncIterable<A>) => Pair<AsyncIterable<I>, AsyncIterable<J>>;
§
partitionMap<A, I, J>(predicate: (a: A) => Either<J, I>): (ua: AsyncIterable<A>) => Pair<AsyncIterable<I>, AsyncIterable<J>>
[src]

§Type Parameters

§Parameters

§
predicate: (a: A) => Either<J, I>
[src]

§Return Type

§
(ua: AsyncIterable<A>) => Pair<AsyncIterable<I>, AsyncIterable<J>>
[src]