import { EMPTY , MonoTypeOperatorFunction , Observable , Operator , Subscriber , TeardownLogic , } from 'rxjs' ; example param count export function takeInArray < T > ( count ) { return function takeLastOperatorFunction ( source ) : Observable < T [ ] > { if ( count === 0 ) { return EMPTY ; } else { return source . lift ( new TakeInArray ( count ) ) ; } } ; } class TakeInArray < T > implements Operator < T [ ] , T [ ] > { constructor ( private total ) { if ( this . total < 0 ) { throw new Error ( 'Cannot take a negative number of items' ) ; } } call ( subscriber , source ) { return source . subscribe ( new TakeInArraySubscriber ( subscriber , this . total ) ) ; } } class TakeInArraySubscriber < T > extends Subscriber < T [ ] > { private current : number = 0 ; constructor ( destination , private total ) { super ( destination ) ; } protected _next ( value ) { const remaining = this . total - this . current ; if ( remaining > value . length ) { this . destination . next ! ( value ) ; this . current += value . length ; } else { this . destination . next ! ( value . slice ( 0 , remaining ) ) ; this . destination . complete ! ( ) ; this . unsubscribe ( ) ; } } }