typescript(option): feat: added a bindAsync helper
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
9236bade0c
commit
b16272a3aa
10
typescript/option/src/helpers/bindAsync.ts
Normal file
10
typescript/option/src/helpers/bindAsync.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { Mapper } from '../internalTypes'
|
||||||
|
import { Option, None } from '../types'
|
||||||
|
import { match } from './match'
|
||||||
|
|
||||||
|
export const bindAsync = <T, U>(
|
||||||
|
binder: Mapper<T, Promise<Option<U>>>,
|
||||||
|
option: Option<T>
|
||||||
|
): Promise<Option<U>> => {
|
||||||
|
return match(binder, Promise.resolve(None), option)
|
||||||
|
}
|
|
@ -17,3 +17,4 @@ export * from './toArray'
|
||||||
export * from './toNullable'
|
export * from './toNullable'
|
||||||
export * from './withDefault'
|
export * from './withDefault'
|
||||||
export * from './mapAsync'
|
export * from './mapAsync'
|
||||||
|
export * from './bindAsync'
|
||||||
|
|
Loading…
Reference in a new issue