Last active
October 24, 2022 16:17
-
-
Save harbirchahal/048a3e270ae925cef56d4f70ba0bf192 to your computer and use it in GitHub Desktop.
Extends Monet js functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://monet.github.io/monet.js/ | |
import { Observable } from 'rxjs'; | |
import { Maybe } from 'monet'; | |
import { filter, map } from 'rxjs/operators'; | |
export function filterIsSome<T extends NonNullable<{}>>() { | |
return function (source: Observable<Maybe<T>>): Observable<Maybe<T>> { | |
return source.pipe(filter((maybe) => maybe.isSome())); | |
}; | |
} | |
export function filterUnwrapSome<T extends NonNullable<{}>>() { | |
return function (source: Observable<Maybe<T>>): Observable<T> { | |
return source.pipe( | |
filter((maybe) => maybe.isSome()), | |
map((maybe) => maybe.some()) | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment