1
Fork 0

typescript(option): feat: using symbols instead of plain strings

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-22 17:48:39 +02:00 committed by prescientmoon
parent 6f93885507
commit 92a5ecbca1
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
4 changed files with 14 additions and 14 deletions

View file

@ -7,8 +7,7 @@ import {
BackFolder,
Nullable
} from './internalTypes'
import { identity } from './internalHelperts'
import { none, some } from './internals'
import { identity, none, some } from './internals'
export const isSome = <T>(option: Option<T>) => option._type === some
export const isNothing = <T>(option: Option<T>) => option._type === none

View file

@ -1 +0,0 @@
export const identity = <T>(v: T) => v

View file

@ -1,7 +1,4 @@
export const some = 'some'
export const none = 'none'
export const identity = <T>(v: T) => v
export type NominalTyped<T, U> = {
_type: T
value: U
}
export const some = Symbol('some')
export const none = Symbol('none')

View file

@ -1,16 +1,21 @@
import { NominalTyped, none, some } from './internals'
import { some, none } from './internals'
export type None = NominalTyped<'none', null>
export type Some<T> = NominalTyped<'some', T>
type NominalTyped<T, U> = {
_type: T
value: U
}
export type None = NominalTyped<typeof none, null>
export type Some<T> = NominalTyped<typeof some, T>
export type Option<T> = Some<T> | None
export const None: Option<any> = {
_type: 'none',
_type: none,
value: null
}
export const Some = <T>(value: T): Option<T> => ({
_type: 'some',
_type: some,
value
})