import { ITaskChainFn , Task } from '../task/task' ; import { UnknownError } from '../task/unknown-error' ; export function chain < T1 , T2 , E2 > ( fn ) { return function < E1 > ( input ) : Task < T2 , E1 | E2 | UnknownError > { return new Task ( ( outerResolve , outerReject ) => { input . fork ( outerReject , value => { try { fn ( value ) . fork ( outerReject , outerResolve ) ; } catch ( err ) { outerReject ( new UnknownError ( err ) ) ; } } ) ; } ) ; } ; }