Skip to content

Commit 7f9e1f6

Browse files
author
Travis CI
committed
Squashed commit of the following: commit 0701ba1e23e280e68921ac9b3941445e7bfa54ea Author: Travis CI <github@fb.com> Date: Fri Sep 29 15:40:12 2017 -0700 Fix spacing and follow ups commit 03d0691de5d663e9877c6e6584ac0659a273cf12 Merge: 07329da f1d3bee Author: Travis CI <github@fb.com> Date: Fri Sep 29 15:15:11 2017 -0700 Merge branch 'zipAll' of https://github.com/arjans/immutable-js into arjans-zipAll commit f1d3bee Author: Aditya K <adityavkk@gmail.com> Date: Thu Mar 30 17:06:56 2017 -0400 run build commit ed0aa0c Author: arjans <arjansingh1989@gmail.com> Date: Thu Mar 30 20:29:12 2017 +0000 Remove redundant boolean cast. commit 03a5f43 Author: arjans <arjansingh1989@gmail.com> Date: Thu Mar 30 20:26:10 2017 +0000 remove parens in single param arrow function commit 6c0e643 Author: arjans <arjansingh1989@gmail.com> Date: Thu Mar 30 20:24:33 2017 +0000 fix linter warnings about commas, let/var, and missing whitespaces commit 2751375 Author: arjans <arjansingh1989@gmail.com> Date: Thu Mar 30 19:56:04 2017 +0000 add documentation and type signatures in flow commit 66d01cc Author: Aditya K <adityavkk@gmail.com> Date: Wed Mar 29 20:09:01 2017 -0400 remove redundant variables in zipWithFactory commit da399c9 Author: Arjan Singh <arjansingh1989@gmail.com> Date: Wed Mar 29 17:06:37 2017 -0700 Get tests working for zipAll commit 4403c04 Author: Aditya K <adityavkk@gmail.com> Date: Wed Mar 29 19:16:47 2017 -0400 add conditional zipSize calculation for zipAll in zipWithFactory commit e84cebb Merge: 58b00c9 2884e76 Author: Aditya K <adityavkk@gmail.com> Date: Wed Mar 29 18:54:01 2017 -0400 Merge branch 'zipAll' of https://github.com/arjans/immutable-js into zipAll commit 58b00c9 Author: Aditya K <adityavkk@gmail.com> Date: Wed Mar 29 18:53:43 2017 -0400 move to const and let in __iteratorUncached commit 2884e76 Author: Arjan Singh <arjansingh1989@gmail.com> Date: Wed Mar 29 15:53:26 2017 -0700 Remove extra spaces. commit c0c8fdc Author: Arjan Singh <arjansingh1989@gmail.com> Date: Wed Mar 29 15:52:38 2017 -0700 Add zipAll to CollectionImpl commit faa2261 Author: Aditya K <adityavkk@gmail.com> Date: Wed Mar 29 18:43:25 2017 -0400 add zipAll handling in __iteratorUncached for zipSequence commit 492cb01 Author: Aditya K <adityavkk@gmail.com> Date: Wed Mar 29 18:39:00 2017 -0400 add zipAll flag to __iteratorUncached in zipSequence
1 parent 07329da commit 7f9e1f6

11 files changed

+602
-35
lines changed

__tests__/zip.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ describe('zip', () => {
6666

6767
});
6868

69+
describe('zipAll', () => {
70+
71+
it('fills in the empty zipped values with undefined', () => {
72+
expect(
73+
Seq([1, 2, 3]).zipAll(Seq([4])).toArray(),
74+
).toEqual(
75+
[[1, 4], [2, undefined], [3, undefined]],
76+
);
77+
});
78+
79+
check.it('is always the size of the longest sequence', [gen.notEmpty(gen.array(gen.posInt))], lengths => {
80+
const ranges = lengths.map(l => Range(0, l));
81+
const first = ranges.shift();
82+
const zipped = first.zipAll.apply(first, ranges);
83+
const longestLength = Math.max.apply(Math, lengths);
84+
expect(zipped.size).toBe(longestLength);
85+
});
86+
87+
});
88+
6989
describe('interleave', () => {
7090

7191
it('interleaves multiple collections', () => {

dist/immutable-nonambient.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,20 @@
891891
*/
892892
zip(...collections: Array<Collection<any, any>>): List<any>;
893893

894+
/**
895+
* Returns a List "zipped" with the provided collections.
896+
*
897+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
898+
* exhausted. Missing values from shorter collections are filled with `undefined`.
899+
*
900+
* ```js
901+
* const a = List([ 1, 2 ]);
902+
* const b = List([ 3, 4, 5 ]);
903+
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
904+
* ```
905+
*/
906+
zipAll(...collections: Array<Collection<any, any>>): List<any>;
907+
894908
/**
895909
* Returns a List "zipped" with the provided collections by using a
896910
* custom `zipper` function.
@@ -2039,6 +2053,23 @@
20392053
*/
20402054
zip(...collections: Array<Collection<any, any>>): OrderedSet<any>;
20412055

2056+
/**
2057+
* Returns a OrderedSet of the same type "zipped" with the provided
2058+
* collections.
2059+
*
2060+
* @see IndexedIterator.zipAll
2061+
*
2062+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
2063+
* exhausted. Missing values from shorter collections are filled with `undefined`.
2064+
*
2065+
* ```js
2066+
* const a = OrderedSet([ 1, 2 ]);
2067+
* const b = OrderedSet([ 3, 4, 5 ]);
2068+
* const c = a.zipAll(b); // OrderedSet [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2069+
* ```
2070+
*/
2071+
zipAll(...collections: Array<Collection<any, any>>): OrderedSet<any>;
2072+
20422073
/**
20432074
* Returns an OrderedSet of the same type "zipped" with the provided
20442075
* collections by using a custom `zipper` function.
@@ -2280,6 +2311,20 @@
22802311
*/
22812312
zip(...collections: Array<Collection<any, any>>): Stack<any>;
22822313

2314+
/**
2315+
* Returns a Stack "zipped" with the provided collections.
2316+
*
2317+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
2318+
* exhausted. Missing values from shorter collections are filled with `undefined`.
2319+
*
2320+
* ```js
2321+
* const a = Stack([ 1, 2 ]);
2322+
* const b = Stack([ 3, 4, 5 ]);
2323+
* const c = a.zipAll(b); // Stack [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2324+
* ```
2325+
*/
2326+
zipAll(...collections: Array<Collection<any, any>>): Stack<any>;
2327+
22832328
/**
22842329
* Returns a Stack "zipped" with the provided collections by using a
22852330
* custom `zipper` function.
@@ -2836,6 +2881,20 @@
28362881
*/
28372882
zip(...collections: Array<Collection<any, any>>): Seq.Indexed<any>;
28382883

2884+
/**
2885+
* Returns a Seq "zipped" with the provided collections.
2886+
*
2887+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
2888+
* exhausted. Missing values from shorter collections are filled with `undefined`.
2889+
*
2890+
* ```js
2891+
* const a = Seq([ 1, 2 ]);
2892+
* const b = Seq([ 3, 4, 5 ]);
2893+
* const c = a.zipAll(b); // Seq [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2894+
* ```
2895+
*/
2896+
zipAll(...collections: Array<Collection<any, any>>): Seq.Indexed<any>;
2897+
28392898
/**
28402899
* Returns a Seq "zipped" with the provided collections by using a
28412900
* custom `zipper` function.
@@ -3411,6 +3470,20 @@
34113470
*/
34123471
zip(...collections: Array<Collection<any, any>>): Collection.Indexed<any>;
34133472

3473+
/**
3474+
* Returns a Collection "zipped" with the provided collections.
3475+
*
3476+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
3477+
* exhausted. Missing values from shorter collections are filled with `undefined`.
3478+
*
3479+
* ```js
3480+
* const a = List([ 1, 2 ]);
3481+
* const b = List([ 3, 4, 5 ]);
3482+
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
3483+
* ```
3484+
*/
3485+
zipAll(...collections: Array<Collection<any, any>>): Collection.Indexed<any>;
3486+
34143487
/**
34153488
* Returns a Collection of the same type "zipped" with the provided
34163489
* collections by using a custom `zipper` function.

dist/immutable.d.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,20 @@ declare module Immutable {
891891
*/
892892
zip(...collections: Array<Collection<any, any>>): List<any>;
893893

894+
/**
895+
* Returns a List "zipped" with the provided collections.
896+
*
897+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
898+
* exhausted. Missing values from shorter collections are filled with `undefined`.
899+
*
900+
* ```js
901+
* const a = List([ 1, 2 ]);
902+
* const b = List([ 3, 4, 5 ]);
903+
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
904+
* ```
905+
*/
906+
zipAll(...collections: Array<Collection<any, any>>): List<any>;
907+
894908
/**
895909
* Returns a List "zipped" with the provided collections by using a
896910
* custom `zipper` function.
@@ -2039,6 +2053,23 @@ declare module Immutable {
20392053
*/
20402054
zip(...collections: Array<Collection<any, any>>): OrderedSet<any>;
20412055

2056+
/**
2057+
* Returns a OrderedSet of the same type "zipped" with the provided
2058+
* collections.
2059+
*
2060+
* @see IndexedIterator.zipAll
2061+
*
2062+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
2063+
* exhausted. Missing values from shorter collections are filled with `undefined`.
2064+
*
2065+
* ```js
2066+
* const a = OrderedSet([ 1, 2 ]);
2067+
* const b = OrderedSet([ 3, 4, 5 ]);
2068+
* const c = a.zipAll(b); // OrderedSet [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2069+
* ```
2070+
*/
2071+
zipAll(...collections: Array<Collection<any, any>>): OrderedSet<any>;
2072+
20422073
/**
20432074
* Returns an OrderedSet of the same type "zipped" with the provided
20442075
* collections by using a custom `zipper` function.
@@ -2280,6 +2311,20 @@ declare module Immutable {
22802311
*/
22812312
zip(...collections: Array<Collection<any, any>>): Stack<any>;
22822313

2314+
/**
2315+
* Returns a Stack "zipped" with the provided collections.
2316+
*
2317+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
2318+
* exhausted. Missing values from shorter collections are filled with `undefined`.
2319+
*
2320+
* ```js
2321+
* const a = Stack([ 1, 2 ]);
2322+
* const b = Stack([ 3, 4, 5 ]);
2323+
* const c = a.zipAll(b); // Stack [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2324+
* ```
2325+
*/
2326+
zipAll(...collections: Array<Collection<any, any>>): Stack<any>;
2327+
22832328
/**
22842329
* Returns a Stack "zipped" with the provided collections by using a
22852330
* custom `zipper` function.
@@ -2836,6 +2881,20 @@ declare module Immutable {
28362881
*/
28372882
zip(...collections: Array<Collection<any, any>>): Seq.Indexed<any>;
28382883

2884+
/**
2885+
* Returns a Seq "zipped" with the provided collections.
2886+
*
2887+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
2888+
* exhausted. Missing values from shorter collections are filled with `undefined`.
2889+
*
2890+
* ```js
2891+
* const a = Seq([ 1, 2 ]);
2892+
* const b = Seq([ 3, 4, 5 ]);
2893+
* const c = a.zipAll(b); // Seq [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2894+
* ```
2895+
*/
2896+
zipAll(...collections: Array<Collection<any, any>>): Seq.Indexed<any>;
2897+
28392898
/**
28402899
* Returns a Seq "zipped" with the provided collections by using a
28412900
* custom `zipper` function.
@@ -3411,6 +3470,20 @@ declare module Immutable {
34113470
*/
34123471
zip(...collections: Array<Collection<any, any>>): Collection.Indexed<any>;
34133472

3473+
/**
3474+
* Returns a Collection "zipped" with the provided collections.
3475+
*
3476+
* Unlike `zip`, `zipAll` continues zipping until the longest collection is
3477+
* exhausted. Missing values from shorter collections are filled with `undefined`.
3478+
*
3479+
* ```js
3480+
* const a = List([ 1, 2 ]);
3481+
* const b = List([ 3, 4, 5 ]);
3482+
* const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
3483+
* ```
3484+
*/
3485+
zipAll(...collections: Array<Collection<any, any>>): Collection.Indexed<any>;
3486+
34143487
/**
34153488
* Returns a Collection of the same type "zipped" with the provided
34163489
* collections by using a custom `zipper` function.

dist/immutable.es.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,9 +1807,10 @@ function maxCompare(comparator, a, b) {
18071807
comp > 0;
18081808
}
18091809

1810-
function zipWithFactory(keyIter, zipper, iters) {
1810+
function zipWithFactory(keyIter, zipper, iters, zipAll) {
18111811
var zipSequence = makeSequence(keyIter);
1812-
zipSequence.size = new ArraySeq(iters).map(function (i) { return i.size; }).min();
1812+
var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
1813+
zipSequence.size = zipAll ? sizes.max() : sizes.min();
18131814
// Note: this a generic base implementation of __iterate in terms of
18141815
// __iterator which may be more generically useful in the future.
18151816
zipSequence.__iterate = function(fn, reverse) {
@@ -1848,7 +1849,7 @@ function zipWithFactory(keyIter, zipper, iters) {
18481849
var steps;
18491850
if (!isDone) {
18501851
steps = iterators.map(function (i) { return i.next(); });
1851-
isDone = steps.some(function (s) { return s.done; });
1852+
isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
18521853
}
18531854
if (isDone) {
18541855
return iteratorDone();
@@ -4990,6 +4991,11 @@ mixin(IndexedCollection, {
49904991
return reify(this, zipWithFactory(this, defaultZipper, collections));
49914992
},
49924993

4994+
zipAll: function zipAll(/*, ...collections */) {
4995+
var collections = [this].concat(arrCopy(arguments));
4996+
return reify(this, zipWithFactory(this, defaultZipper, collections, true));
4997+
},
4998+
49934999
zipWith: function zipWith(zipper /*, ...collections */) {
49945000
var collections = arrCopy(arguments);
49955001
collections[0] = this;

dist/immutable.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,9 +1813,10 @@ function maxCompare(comparator, a, b) {
18131813
comp > 0;
18141814
}
18151815

1816-
function zipWithFactory(keyIter, zipper, iters) {
1816+
function zipWithFactory(keyIter, zipper, iters, zipAll) {
18171817
var zipSequence = makeSequence(keyIter);
1818-
zipSequence.size = new ArraySeq(iters).map(function (i) { return i.size; }).min();
1818+
var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
1819+
zipSequence.size = zipAll ? sizes.max() : sizes.min();
18191820
// Note: this a generic base implementation of __iterate in terms of
18201821
// __iterator which may be more generically useful in the future.
18211822
zipSequence.__iterate = function(fn, reverse) {
@@ -1854,7 +1855,7 @@ function zipWithFactory(keyIter, zipper, iters) {
18541855
var steps;
18551856
if (!isDone) {
18561857
steps = iterators.map(function (i) { return i.next(); });
1857-
isDone = steps.some(function (s) { return s.done; });
1858+
isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
18581859
}
18591860
if (isDone) {
18601861
return iteratorDone();
@@ -4996,6 +4997,11 @@ mixin(IndexedCollection, {
49964997
return reify(this, zipWithFactory(this, defaultZipper, collections));
49974998
},
49984999

5000+
zipAll: function zipAll(/*, ...collections */) {
5001+
var collections = [this].concat(arrCopy(arguments));
5002+
return reify(this, zipWithFactory(this, defaultZipper, collections, true));
5003+
},
5004+
49995005
zipWith: function zipWith(zipper /*, ...collections */) {
50005006
var collections = arrCopy(arguments);
50015007
collections[0] = this;

0 commit comments

Comments
 (0)