From e2e085cbc35a0c076270705a2a92b411ca5d88fd Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Mon, 23 Dec 2019 14:04:52 +0200 Subject: [PATCH] typescript(option): fix: fied broken brand equality Signed-off-by: prescientmoon --- typescript/option/src/helpers/get.ts | 4 ++-- typescript/option/src/helpers/isSome.ts | 4 ++-- typescript/option/src/helpers/iter.ts | 4 ++-- typescript/option/src/helpers/match.ts | 4 ++-- typescript/option/src/types.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/typescript/option/src/helpers/get.ts b/typescript/option/src/helpers/get.ts index 7ed7e2a..72fc4de 100644 --- a/typescript/option/src/helpers/get.ts +++ b/typescript/option/src/helpers/get.ts @@ -1,8 +1,8 @@ -import { some } from '../internals' import { Option } from '../types' +import { isSome } from './isSome' export const get = (option: Option): T => { - if (option.__brand === some) { + if (isSome(option)) { return option as T } diff --git a/typescript/option/src/helpers/isSome.ts b/typescript/option/src/helpers/isSome.ts index cbc07ca..51fd00c 100644 --- a/typescript/option/src/helpers/isSome.ts +++ b/typescript/option/src/helpers/isSome.ts @@ -1,4 +1,4 @@ import { Option } from '../types' -import { some } from '../internals' +import { isNothing } from './isNone' -export const isSome = (option: Option) => option.__brand === some +export const isSome = (option: Option) => !isNothing(option) diff --git a/typescript/option/src/helpers/iter.ts b/typescript/option/src/helpers/iter.ts index 8788b09..6c8108f 100644 --- a/typescript/option/src/helpers/iter.ts +++ b/typescript/option/src/helpers/iter.ts @@ -1,9 +1,9 @@ -import { some } from '../internals' import { Mapper } from '../internalTypes' import { Option } from '../types' +import { isSome } from './isSome' export const iter = (mapper: Mapper, option: Option) => { - if (option.__brand === some) { + if (isSome(option)) { mapper(option as T) } } diff --git a/typescript/option/src/helpers/match.ts b/typescript/option/src/helpers/match.ts index 4e3e4d2..dda77b6 100644 --- a/typescript/option/src/helpers/match.ts +++ b/typescript/option/src/helpers/match.ts @@ -1,13 +1,13 @@ import { Option } from '../types' import { Mapper } from '../internalTypes' -import { some } from '../internals' +import { isSome } from './isSome' export const match = ( caseSome: Mapper, _default: U, option: Option ) => { - if (option.__brand === some) { + if (isSome(option)) { return caseSome(option as T) } diff --git a/typescript/option/src/types.ts b/typescript/option/src/types.ts index e95dca5..ae443bb 100644 --- a/typescript/option/src/types.ts +++ b/typescript/option/src/types.ts @@ -6,5 +6,5 @@ type Some = Brand export type Option = Some | None -export const None = undefined as None -export const Some = (value: T): Option => value as Some +export const None = { __brand: none } as None +export const Some = (value: T) => value as Option