1
Fork 0

typescript(option): feat: added a withDefault hepler

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-19 14:20:47 +02:00 committed by prescientmoon
parent 0458b226c7
commit 4ebe549c29
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 6 additions and 0 deletions

View file

@ -16,6 +16,8 @@ npm install @adrielus/option
Curently there are no docs, but all functions have the same type definition as the ones from [fsharp](https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/core.option-module-%5Bfsharp%5D) (except the ones from my package are not curreied)
There are also a few original helpers (match, and withDefault), but I'ts pretty easy to guess what those do
# Contributing
First, clone this repo:

View file

@ -85,3 +85,7 @@ export const toArray = <T>(option: Option<T>) => {
export const toNullable = <T>(option: Option<T>) => {
return match(option, identity, always(null))
}
export const withDefault = <T>(_default: T, option: Option<T>) => {
return match(option, identity, always(_default))
}