typescript(option): feat: added a withDefault hepler
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
0458b226c7
commit
4ebe549c29
|
@ -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:
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue