1
Fork 0

typescript(option): chore: fixed build process

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-22 17:38:10 +02:00 committed by prescientmoon
parent 906096a5cb
commit 6f93885507
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
6 changed files with 1132 additions and 153 deletions
typescript/option/src

View file

@ -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)
}
}

View file

@ -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
}

View file

@ -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
})