namespace Pipeline { function * generateRandomNumbers ( ) { while ( true ) { yield Math . random ( ) ; } } function * square ( iter ) { for ( const value of iter ) { yield value ** 2 ; } } function * take < T > ( iter , n ) { for ( const value of iter ) { if ( n -- <= 0 ) return ; yield value ; } } const values = take ( square ( generateRandomNumbers ( ) ) , 5 ) ; for ( const value of values ) { console . log ( value ) ; } }