typescript(option): fix: fied broken brand equality
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
729b901bc5
commit
e2e085cbc3
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue