Bladeren bron

Flatten function arrays.

Eugene Lazutkin 3 jaren geleden
bovenliggende
commit
5e55b23f1c
3 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  1. 1 1
      src/fun.js
  2. 1 1
      src/gen.js
  3. 2 2
      src/index.js

+ 1 - 1
src/fun.js

@@ -72,7 +72,7 @@ const flush = async (fns, index, collect) => {
 };
 
 const collect = (collect, fns) => {
-  fns = fns.filter(fn => fn);
+  fns = fns.filter(fn => fn).flat(Infinity);
   if (!fns.length) {
     fns = [x => x];
   }

+ 1 - 1
src/gen.js

@@ -51,7 +51,7 @@ const next = async function* (value, fns, index) {
 };
 
 const gen = (...fns) => {
-  fns = fns.filter(fn => fn);
+  fns = fns.filter(fn => fn).flat(Infinity);
   if (!fns.length) {
     fns = [x => x];
   }

+ 2 - 2
src/index.js

@@ -97,10 +97,10 @@ const read = output => {
 
 const chain = (fns, options) => {
   if (!Array.isArray(fns) || !fns.length) {
-    throw TypeError("Chain's argument should be a non-empty array.");
+    throw TypeError("Chain's first argument should be a non-empty array.");
   }
 
-  fns = fns.filter(fn => fn); // remove nulls
+  fns = fns.filter(fn => fn).flat(Infinity); // remove nulls and flatten
 
   const streams = (
       options && options.noGrouping