Skip to content

Conversation

Milly
Copy link

@Milly Milly commented Apr 6, 2023

We can convert the type of item by specifying a type-guard function to filter.
Note that this is not available for async filter functions, because Typescript does not have async type-guard syntax.

import { asynciter } from "./asynciter.ts";

const isString = (item: unknown): item is string => typeof item === "string";

const iter = asynciter(["foo", 42]); // => IAsyncIter<string | number>

const stringIter = iter.filter(isString); // => IAsyncIter<string>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant