1
Fork 0

typescript(option): fix: fied broken brand equality

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-23 14:04:52 +02:00 committed by prescientmoon
parent 729b901bc5
commit e2e085cbc3
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
5 changed files with 10 additions and 10 deletions

View file

@ -1,8 +1,8 @@
import { some } from '../internals'
import { Option } from '../types' import { Option } from '../types'
import { isSome } from './isSome'
export const get = <T>(option: Option<T>): T => { export const get = <T>(option: Option<T>): T => {
if (option.__brand === some) { if (isSome(option)) {
return option as T return option as T
} }

View file

@ -1,4 +1,4 @@
import { Option } from '../types' import { Option } from '../types'
import { some } from '../internals' import { isNothing } from './isNone'
export const isSome = <T>(option: Option<T>) => option.__brand === some export const isSome = <T>(option: Option<T>) => !isNothing(option)

View file

@ -1,9 +1,9 @@
import { some } from '../internals'
import { Mapper } from '../internalTypes' import { Mapper } from '../internalTypes'
import { Option } from '../types' import { Option } from '../types'
import { isSome } from './isSome'
export const iter = <T>(mapper: Mapper<T, void>, option: Option<T>) => { export const iter = <T>(mapper: Mapper<T, void>, option: Option<T>) => {
if (option.__brand === some) { if (isSome(option)) {
mapper(option as T) mapper(option as T)
} }
} }

View file

@ -1,13 +1,13 @@
import { Option } from '../types' import { Option } from '../types'
import { Mapper } from '../internalTypes' import { Mapper } from '../internalTypes'
import { some } from '../internals' import { isSome } from './isSome'
export const match = <T, U>( export const match = <T, U>(
caseSome: Mapper<T, U>, caseSome: Mapper<T, U>,
_default: U, _default: U,
option: Option<T> option: Option<T>
) => { ) => {
if (option.__brand === some) { if (isSome(option)) {
return caseSome(option as T) return caseSome(option as T)
} }

View file

@ -6,5 +6,5 @@ type Some<T> = Brand<T, typeof some>
export type Option<T> = Some<T> | None export type Option<T> = Some<T> | None
export const None = undefined as None export const None = { __brand: none } as None
export const Some = <T>(value: T): Option<T> => value as Some<T> export const Some = <T>(value: T) => value as Option<T>