typescript(option): refactor: now using @thi.ng/compose
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
0abd53917b
commit
0ef7baa739
9 changed files with 27 additions and 9 deletions
typescript/option/src
|
@ -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)
|
||||
|
|
|
@ -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> => {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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>) => {
|
||||
|
|
|
@ -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>) => {
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
export const identity = <T>(v: T) => v
|
||||
|
||||
export const none = Symbol('none')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue