Skip to content
Merged
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
9 changes: 9 additions & 0 deletions ambar-core/src/maybe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {
CallableJust as Just,
CallableNothing as Nothing,
from,
fromNullable,
catMaybes,
mapMaybe,
};
Expand Down Expand Up @@ -99,6 +100,14 @@ function from<T>(v: undefined | T): Maybe<T> {
}
}

function fromNullable<T>(v: NonNullable<T> | null): Maybe<T> {
if (v === null) {
return new Nothing();
} else {
return new Just(v);
}
}

// Remove Nothings from an array.
function catMaybes<T>(xs: Array<Maybe<T>>): Array<T> {
const r: Array<T> = [];
Expand Down