From 44bac95ea8c73e62f055d714f870c9e496ff2da6 Mon Sep 17 00:00:00 2001 From: Minsang Kim Date: Sun, 11 Feb 2024 18:30:05 +0900 Subject: [PATCH] feat: O.filter with guard compatible overload --- docs/api/generated/_option.mdx | 2 ++ src/Option/Option.ts | 4 ++++ src/Option/index.ts | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/docs/api/generated/_option.mdx b/docs/api/generated/_option.mdx index acbd079..7eae8cc 100644 --- a/docs/api/generated/_option.mdx +++ b/docs/api/generated/_option.mdx @@ -21,6 +21,8 @@ Returns `Some(value)` if `option` is `Some(value)` and the result of `predicateF ```ts function filter(option: Option, predicateFn: (value: A) => boolean): Option function filter(predicateFn: (value: A) => boolean): (option: Option) => Option +function filter(option: Option, predicateFn: (value: A) => value is B): Option +function filter(predicateFn: (value: A) => value is B): (option: Option) => Option ``` ```ts diff --git a/src/Option/Option.ts b/src/Option/Option.ts index 529eab9..a82e169 100644 --- a/src/Option/Option.ts +++ b/src/Option/Option.ts @@ -35,6 +35,10 @@ export declare function filter( option: Option, predicateFn: (value: A) => boolean, ): Option +export declare function filter( + option: Option, + predicateFn: (value: A) => value is B, +): Option export declare function map( option: Option, mapFn: (value: A) => NonNullable, diff --git a/src/Option/index.ts b/src/Option/index.ts index d5db33b..2844382 100644 --- a/src/Option/index.ts +++ b/src/Option/index.ts @@ -106,6 +106,17 @@ export declare function filter( predicateFn: (value: A) => boolean, ): (option: Option) => Option +/** Returns `Some(value)` if `option` is `Some(value)` and the result of `predicateFn` is truthy, otherwise, returns `None`. */ + +export declare function filter( + option: Option, + predicateFn: (value: A) => value is B, +): Option + +export declare function filter( + predicateFn: (value: A) => value is B, +): (option: Option) => Option + /** Returns `value` if `option` is `Some(value)`, otherwise, returns a default value. */ export declare function getWithDefault>(