Skip to content

Instantly share code, notes, and snippets.

@harbirchahal
Last active October 24, 2022 16:17
Show Gist options
  • Save harbirchahal/048a3e270ae925cef56d4f70ba0bf192 to your computer and use it in GitHub Desktop.
Save harbirchahal/048a3e270ae925cef56d4f70ba0bf192 to your computer and use it in GitHub Desktop.
Extends Monet js functionality
// 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