since import { Alt , Alt1 , Alt2 } from 'fp-ts/lib/Alt' ; import { flow } from 'fp-ts/lib/function' ; import { HKT , Kind , Kind2 , URIS , URIS2 } from 'fp-ts/lib/HKT' ; import { Monad , Monad1 , Monad2 } from 'fp-ts/lib/Monad' ; import { fold , Option } from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; example since export function collectUntil < M extends URIS2 , F extends URIS > ( M , F ) ; export function collectUntil < M extends URIS , F extends URIS2 > ( M , F ) ; export function collectUntil < M extends URIS , F extends URIS > ( M , F ) ; export function collectUntil < M , F > ( M , F ) ; export function collectUntil < M , F > ( M , F ) { return < I , A > ( f ) : ( ( i : I ) => HKT < M , HKT < F , A > > ) => { const go = ( mfa ) : HKT < M , HKT < F , A > > => { return M . chain ( mfa , ( [ fx , oi ] ) => { return pipe ( oi , fold ( ( ) => M . of ( fx ) , ( i ) => go ( M . map ( f ( i ) , ( [ fy , oi ] ) => [ F . alt ( fx , ( ) => fy ) , oi ] ) ) ) ) ; } ) ; } ; return flow ( f , go ) ; } ; }