@@ -1807,9 +1807,13 @@ function maxCompare(comparator, a, b) {
1807
1807
comp > 0 ;
1808
1808
}
1809
1809
1810
- function zipWithFactory ( keyIter , zipper , iters ) {
1810
+ function zipWithFactory ( keyIter , zipper , iters , zipAll ) {
1811
1811
var zipSequence = makeSequence ( keyIter ) ;
1812
1812
zipSequence . size = new ArraySeq ( iters ) . map ( function ( i ) { return i . size ; } ) . min ( ) ;
1813
+ var sizes = new ArraySeq ( iters ) . map ( function ( i ) { return i . size ; } ) ;
1814
+ var zipSize = ! ! zipAll ? sizes . max ( ) : sizes . min ( ) ;
1815
+ zipSequence . size = zipSize ;
1816
+
1813
1817
// Note: this a generic base implementation of __iterate in terms of
1814
1818
// __iterator which may be more generically useful in the future.
1815
1819
zipSequence . __iterate = function ( fn , reverse ) {
@@ -1838,28 +1842,32 @@ function zipWithFactory(keyIter, zipper, iters) {
1838
1842
}
1839
1843
return iterations ;
1840
1844
} ;
1845
+
1841
1846
zipSequence . __iteratorUncached = function ( type , reverse ) {
1842
- var iterators = iters . map (
1843
- function ( i ) { return ( ( i = Collection ( i ) ) , getIterator ( reverse ? i . reverse ( ) : i ) ) ; }
1847
+ var iterators = iters . map ( function ( i ) { return ( i = Collection ( i ) , getIterator ( reverse ? i . reverse ( ) : i ) ) ; }
1844
1848
) ;
1845
1849
var iterations = 0 ;
1846
1850
var isDone = false ;
1847
1851
return new Iterator ( function ( ) {
1848
1852
var steps ;
1849
1853
if ( ! isDone ) {
1850
1854
steps = iterators . map ( function ( i ) { return i . next ( ) ; } ) ;
1851
- isDone = steps . some ( function ( s ) { return s . done ; } ) ;
1855
+ if ( zipAll ) { isDone = steps . every ( function ( s ) { return s . done ; } ) ; }
1856
+ else { isDone = steps . some ( function ( s ) { return s . done ; } ) ; }
1852
1857
}
1858
+
1853
1859
if ( isDone ) {
1854
1860
return iteratorDone ( ) ;
1855
1861
}
1862
+
1856
1863
return iteratorValue (
1857
1864
type ,
1858
1865
iterations ++ ,
1859
- zipper . apply ( null , steps . map ( function ( s ) { return s . value ; } ) )
1866
+ zipper . apply ( null , steps . map ( function ( s ) { return s . done ? undefined : s . value ; } ) )
1860
1867
) ;
1861
1868
} ) ;
1862
1869
} ;
1870
+
1863
1871
return zipSequence ;
1864
1872
}
1865
1873
@@ -4975,6 +4983,11 @@ mixin(IndexedCollection, {
4975
4983
return reify ( this , zipWithFactory ( this , defaultZipper , collections ) ) ;
4976
4984
} ,
4977
4985
4986
+ zipAll : function zipAll ( /*, ...collections */ ) {
4987
+ var collections = [ this ] . concat ( arrCopy ( arguments ) ) ;
4988
+ return reify ( this , zipWithFactory ( this , defaultZipper , collections , true ) ) ;
4989
+ } ,
4990
+
4978
4991
zipWith : function zipWith ( zipper /*, ...collections */ ) {
4979
4992
var collections = arrCopy ( arguments ) ;
4980
4993
collections [ 0 ] = this ;
0 commit comments