MCPcopy
hub / github.com/immutable-js/immutable-js / zipWithFactory

Function zipWithFactory

src/Operations.js:872–930  ·  view source on GitHub ↗
(keyIter, zipper, iters, zipAll)

Source from the content-addressed store, hash-verified

870}
871
872export function zipWithFactory(keyIter, zipper, iters, zipAll) {
873 const zipSequence = makeSequence(keyIter);
874 const sizes = new ArraySeq(iters).map((i) => i.size);
875 zipSequence.size = zipAll ? sizes.max() : sizes.min();
876 // Note: this a generic base implementation of __iterate in terms of
877 // __iterator which may be more generically useful in the future.
878 zipSequence.__iterate = function (fn, reverse) {
879 /* generic:
880 var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
881 var step;
882 var iterations = 0;
883 while (!(step = iterator.next()).done) {
884 iterations++;
885 if (fn(step.value[1], step.value[0], this) === false) {
886 break;
887 }
888 }
889 return iterations;
890 */
891 // indexed:
892 const iterator = this.__iterator(ITERATE_VALUES, reverse);
893 let step;
894 let iterations = 0;
895 while (!(step = iterator.next()).done) {
896 if (fn(step.value, iterations++, this) === false) {
897 break;
898 }
899 }
900 return iterations;
901 };
902 zipSequence.__iteratorUncached = function (type, reverse) {
903 const iterators = iters.map(
904 (i) => ((i = Collection(i)), getIterator(reverse ? i.reverse() : i))
905 );
906 let iterations = 0;
907 let isDone = false;
908 return new Iterator(() => {
909 let steps;
910 if (!isDone) {
911 steps = iterators.map((i) => i.next());
912 isDone = zipAll
913 ? steps.every((s) => s.done)
914 : steps.some((s) => s.done);
915 }
916 if (isDone) {
917 return iteratorDone();
918 }
919 return iteratorValue(
920 type,
921 iterations++,
922 zipper.apply(
923 null,
924 steps.map((s) => s.value)
925 )
926 );
927 });
928 };
929 return zipSequence;

Callers 4

interleaveFunction · 0.90
zipFunction · 0.90
zipAllFunction · 0.90
zipWithFunction · 0.90

Calls 13

CollectionClass · 0.90
getIteratorFunction · 0.90
iteratorDoneFunction · 0.90
iteratorValueFunction · 0.90
makeSequenceFunction · 0.85
maxMethod · 0.80
minMethod · 0.80
nextMethod · 0.80
everyMethod · 0.80
someMethod · 0.80
mapMethod · 0.65
reverseMethod · 0.65

Tested by

no test coverage detected