From 4ebe549c293c76921fb9f40854dc55fb7b303f30 Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Thu, 19 Dec 2019 14:20:47 +0200 Subject: [PATCH] typescript(option): feat: added a withDefault hepler Signed-off-by: prescientmoon --- typescript/option/README.md | 2 ++ typescript/option/src/helpers.ts | 4 ++++ 2 files changed, 6 insertions(+) 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)) +}