import '../iterablehelpers' ; import { toArray } from 'ix/iterable' ; import { flat } from 'ix/iterable/operators' ; function compareArrays < T > ( fst , snd ) { expect ( fst . toString ( ) ) . toBe ( snd . toString ( ) ) ; } test ( 'Iterable#flat flats all' , ( ) => { const xs = [ 1 , [ 2 , [ 3 ] ] , 4 ] ; const ys = toArray ( flat ( ) ( xs ) ) ; compareArrays ( ys , [ 1 , 2 , 3 , 4 ] ) ; } ) ; test ( 'Iterable#flat flats two layers' , ( ) => { const xs = [ 1 , [ 2 , [ 3 ] ] , 4 ] ; const ys = toArray ( flat ( 2 ) ( xs ) ) ; compareArrays ( ys , [ 1 , 2 , 3 , 4 ] ) ; } ) ; test ( 'Iterable#flat flats one layer' , ( ) => { const xs = [ 1 , [ 2 , [ 3 ] ] , 4 ] ; const ys = toArray ( flat ( 1 ) ( xs ) ) ; compareArrays ( ys , [ 1 , 2 , [ 3 ] , 4 ] ) ; } ) ; test ( 'Iterable#flat flats no layers' , ( ) => { const xs = [ 1 , [ 2 , [ 3 ] ] , 4 ] ; const ys = toArray ( flat ( 1 ) ( xs ) ) ; compareArrays ( ys , [ 1 , [ 2 , [ 3 ] ] , 4 ] ) ; } ) ;