Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add overload to filter with typeguard predicate #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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