From 689c7466824dd5990b106e31aad47c45d0031c1d Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Fri, 20 Dec 2019 14:54:40 +0200 Subject: [PATCH] typescript(option): refactor: islotated T | null in a Nullable internal type and updated the docs Signed-off-by: prescientmoon --- typescript/option/docs/main.md | 2 +- typescript/option/src/helpers.ts | 11 +++++++++-- typescript/option/src/internalTypes.ts | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/typescript/option/docs/main.md b/typescript/option/docs/main.md index e2c05a2..db1f2ec 100644 --- a/typescript/option/docs/main.md +++ b/typescript/option/docs/main.md @@ -194,7 +194,7 @@ A function to create options from nullable values. ### Signature ```ts -const fromNullable: (value: T | null) => Option +const fromNullable: (value: Nullable) => Option ``` ### Usage diff --git a/typescript/option/src/helpers.ts b/typescript/option/src/helpers.ts index 09a419f..629e830 100644 --- a/typescript/option/src/helpers.ts +++ b/typescript/option/src/helpers.ts @@ -1,5 +1,12 @@ import { Option, Some, None } from './types' -import { Binder, Folder, Mapper, Predicate, BackFolder } from './internalTypes' +import { + Binder, + Folder, + Mapper, + Predicate, + BackFolder, + Nullable +} from './internalTypes' import { always, identity } from './internalHelperts' import Internals, { SomeClass, isOption } from './internals' @@ -106,6 +113,6 @@ export const flat = (option: Option): Option => { ) } -export const fromNullable = (value: null | T): Option => { +export const fromNullable = (value: Nullable): Option => { return value === null ? None : Some(value) } diff --git a/typescript/option/src/internalTypes.ts b/typescript/option/src/internalTypes.ts index a636b21..091ab91 100644 --- a/typescript/option/src/internalTypes.ts +++ b/typescript/option/src/internalTypes.ts @@ -5,3 +5,4 @@ export type Binder = Mapper> export type Predicate = Mapper export type Folder = (s: U, v: T) => U export type BackFolder = (v: T, s: U) => U +export type Nullable = T | null