diff --git a/typescript/option/README.md b/typescript/option/README.md index 2ec954c..7aefdc9 100644 --- a/typescript/option/README.md +++ b/typescript/option/README.md @@ -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: diff --git a/typescript/option/src/helpers.ts b/typescript/option/src/helpers.ts index 3d68a9c..7e4017c 100644 --- a/typescript/option/src/helpers.ts +++ b/typescript/option/src/helpers.ts @@ -85,3 +85,7 @@ export const toArray = (option: Option) => { export const toNullable = (option: Option) => { return match(option, identity, always(null)) } + +export const withDefault = (_default: T, option: Option) => { + return match(option, identity, always(_default)) +}