1
Fork 0

typescript(option): refactor: now using @thi.ng/compose

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2019-12-23 15:08:36 +02:00 committed by prescientmoon
parent 0abd53917b
commit 0ef7baa739
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
9 changed files with 27 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import { Option } from '../types'
import { isSome } from './isSome'
import { compL } from '@thi.ng/compose'
export const count = <T>(option: Option<T>) => Number(isSome(option))
export const count = compL(isSome, Number)

View file

@ -1,5 +1,5 @@
import { bind } from './bind'
import { identity } from '../internals'
import { identity } from '@thi.ng/compose'
import { Option } from '../types'
export const flat = <T>(option: Option<Option<T>>): Option<T> => {

View file

@ -1,10 +1,11 @@
import { match } from './match'
import { Mapper } from '../internalTypes'
import { Option, Some, None } from '../types'
import { compL } from '@thi.ng/compose'
export const map = <T, U>(
mapper: Mapper<T, U>,
option: Option<T>
): Option<U> => {
return match(v => Some(mapper(v)), None, option)
return match(compL(mapper, Some), None, option)
}

View file

@ -1,5 +1,5 @@
import { match } from './match'
import { identity } from '../internals'
import { identity } from '@thi.ng/compose'
import { Option } from '../types'
export const toNullable = <T>(option: Option<T>) => {

View file

@ -1,5 +1,5 @@
import { match } from './match'
import { identity } from '../internals'
import { identity } from '@thi.ng/compose'
import { Option } from '../types'
export const withDefault = <T>(_default: T, option: Option<T>) => {

View file

@ -1,3 +1 @@
export const identity = <T>(v: T) => v
export const none = Symbol('none')

View file

@ -1,5 +1,6 @@
import { none, identity } from './internals'
import { identity } from '@thi.ng/compose'
import { Brand } from 'utility-types'
import { none } from './internals'
// This is never actually used outside of typing so we can just declare it
declare const some: unique symbol