@ ObjectiveCName ( "flatMap:" ) public < R > Promise < R > flatMap ( final Function < T , Promise < R > > res ) { final Promise < T > self = this ; return new Promise <> ( ( PromiseFunc < R > ) resolver -> { self . then ( t -> { Promise < R > promise ; try { promise = res . apply ( t ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; resolver . tryError ( e ) ; return ; } promise . then ( t2 -> resolver . result ( t2 ) ) ; promise . failure ( e -> resolver . error ( e ) ) ; } ) ; self . failure ( e -> resolver . error ( e ) ) ; } ) ; }
Map result of promise to promise of value