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

feat: O.filter with guard compatible overload #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/generated/_option.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Returns `Some(value)` if `option` is `Some(value)` and the result of `predicateF
```ts
function filter<A>(option: Option<A>, predicateFn: (value: A) => boolean): Option<A>
function filter<A>(predicateFn: (value: A) => boolean): (option: Option<A>) => Option<A>
function filter<A, B extends A>(option: Option<A>, predicateFn: (value: A) => value is B): Option<B>
function filter<A, B extends A>(predicateFn: (value: A) => value is B): (option: Option<A>) => Option<B>
```

```ts
Expand Down
4 changes: 4 additions & 0 deletions src/Option/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export declare function filter<A>(
option: Option<A>,
predicateFn: (value: A) => boolean,
): Option<A>
export declare function filter<A,B extends A>(
option: Option<A>,
predicateFn: (value: A) => value is B,
): Option<B>
export declare function map<A, B>(
option: Option<A>,
mapFn: (value: A) => NonNullable<B>,
Expand Down
11 changes: 11 additions & 0 deletions src/Option/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ export declare function filter<A>(
predicateFn: (value: A) => boolean,
): (option: Option<A>) => Option<A>

/** Returns `Some(value)` if `option` is `Some(value)` and the result of `predicateFn` is truthy, otherwise, returns `None`. */

export declare function filter<A, B extends A>(
option: Option<A>,
predicateFn: (value: A) => value is B,
): Option<B>

export declare function filter<A, B extends A>(
predicateFn: (value: A) => value is B,
): (option: Option<A>) => Option<B>

/** Returns `value` if `option` is `Some(value)`, otherwise, returns a default value. */

export declare function getWithDefault<A extends NonNullable<any>>(
Expand Down