typescript(option): chore: fixed build process
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
906096a5cb
commit
6f93885507
6 changed files with 1132 additions and 153 deletions
typescript/option/src
|
@ -10,18 +10,16 @@ import {
|
|||
import { identity } from './internalHelperts'
|
||||
import { none, some } from './internals'
|
||||
|
||||
export const isSome = <T>(option: Option<T>): option is Some<T> =>
|
||||
option.type === some
|
||||
export const isNothing = <T>(option: Option<T>): option is None =>
|
||||
option.type === none
|
||||
export const isSome = <T>(option: Option<T>) => option._type === some
|
||||
export const isNothing = <T>(option: Option<T>) => option._type === none
|
||||
|
||||
const match = <T, U>(
|
||||
caseSome: Mapper<T, U>,
|
||||
_default: U,
|
||||
option: Option<T>
|
||||
) => {
|
||||
if (isSome(option)) {
|
||||
return caseSome(option.value as T)
|
||||
if (option._type === some) {
|
||||
return caseSome(option.value)
|
||||
}
|
||||
|
||||
return _default
|
||||
|
@ -72,7 +70,7 @@ export const forall = <T>(predicate: Predicate<T>, option: Option<T>) => {
|
|||
}
|
||||
|
||||
export const get = <T>(option: Option<T>): T => {
|
||||
if (isSome(option)) {
|
||||
if (option._type === some) {
|
||||
return option.value
|
||||
}
|
||||
|
||||
|
@ -80,7 +78,7 @@ export const get = <T>(option: Option<T>): T => {
|
|||
}
|
||||
|
||||
export const iter = <T>(mapper: Mapper<T, void>, option: Option<T>) => {
|
||||
if (isSome(option)) {
|
||||
if (option._type === some) {
|
||||
mapper(option.value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export const some = Symbol('some')
|
||||
export const none = Symbol('none')
|
||||
export const some = 'some'
|
||||
export const none = 'none'
|
||||
|
||||
export type NominalTyped<T, U> = {
|
||||
type: T
|
||||
_type: T
|
||||
value: U
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import { NominalTyped, none, some } from './internals'
|
||||
|
||||
export type None = NominalTyped<typeof none, null>
|
||||
export type Some<T> = NominalTyped<typeof some, T>
|
||||
export type None = NominalTyped<'none', null>
|
||||
export type Some<T> = NominalTyped<'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
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue