Browse Source

Removed support for iterable objects.

They should be marked separately.
Eugene Lazutkin 3 years ago
parent
commit
55d0a22ad8
4 changed files with 5 additions and 32 deletions
  1. 1 7
      src/fun.js
  2. 1 7
      src/gen.js
  3. 2 17
      src/index.js
  4. 1 1
      tests/test-simple.mjs

+ 1 - 7
src/fun.js

@@ -73,13 +73,7 @@ const flush = async (fns, index, collect) => {
 
 
 const collect = (collect, fns) => {
 const collect = (collect, fns) => {
   fns = fns.filter(fn => fn);
   fns = fns.filter(fn => fn);
-  if (fns.length) {
-    if (Symbol.asyncIterator && fns[0][Symbol.asyncIterator]) {
-      fns[0] = fns[0][Symbol.asyncIterator].bind(fns[0]);
-    } else if (Symbol.iterator && fns[0][Symbol.iterator]) {
-      fns[0] = fns[0][Symbol.iterator].bind(fns[0]);
-    }
-  } else {
+  if (!fns.length) {
     fns = [x => x];
     fns = [x => x];
   }
   }
   let flushed = false;
   let flushed = false;

+ 1 - 7
src/gen.js

@@ -52,13 +52,7 @@ const next = async function* (value, fns, index) {
 
 
 const gen = (...fns) => {
 const gen = (...fns) => {
   fns = fns.filter(fn => fn);
   fns = fns.filter(fn => fn);
-  if (fns.length) {
-    if (Symbol.asyncIterator && fns[0][Symbol.asyncIterator]) {
-      fns[0] = fns[0][Symbol.asyncIterator].bind(fns[0]);
-    } else if (Symbol.iterator && fns[0][Symbol.iterator]) {
-      fns[0] = fns[0][Symbol.iterator].bind(fns[0]);
-    }
-  } else {
+  if (!fns.length) {
     fns = [x => x];
     fns = [x => x];
   }
   }
   let flushed = false;
   let flushed = false;

+ 2 - 17
src/index.js

@@ -28,13 +28,6 @@ const isDuplexNodeStream = obj =>
   typeof obj.on === 'function' &&
   typeof obj.on === 'function' &&
   typeof obj.write === 'function';
   typeof obj.write === 'function';
 
 
-const getIterator = x => {
-  if (!x) return null;
-  if (typeof x[Symbol.asyncIterator] == 'function') return x[Symbol.asyncIterator].bind(x);
-  if (typeof x[Symbol.iterator] == 'function') return x[Symbol.iterator].bind(x);
-  return null;
-};
-
 const groupFunctions = (output, fn, index, fns) => {
 const groupFunctions = (output, fn, index, fns) => {
   if (
   if (
     isDuplexNodeStream(fn) ||
     isDuplexNodeStream(fn) ||
@@ -44,12 +37,7 @@ const groupFunctions = (output, fn, index, fns) => {
     output.push(fn);
     output.push(fn);
     return output;
     return output;
   }
   }
-  if (typeof fn != 'function') {
-    const iterator = getIterator(fn);
-    if (!iterator)
-      throw TypeError('Item #' + index + ' is not a proper stream, function, nor iterable.');
-    fn = iterator;
-  }
+  if (typeof fn != 'function') throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');
   if (!output.length) output.push([]);
   if (!output.length) output.push([]);
   const last = output[output.length - 1];
   const last = output[output.length - 1];
   if (Array.isArray(last)) {
   if (Array.isArray(last)) {
@@ -78,10 +66,7 @@ const wrapFunctions = (fn, index, fns) => {
     return fn; // an acceptable stream
     return fn; // an acceptable stream
   }
   }
   if (typeof fn == 'function') return chain.asStream(fn); // a function
   if (typeof fn == 'function') return chain.asStream(fn); // a function
-  const iterator = getIterator(fn);
-  if (!iterator)
-    throw TypeError('Item #' + index + ' is not a proper stream, function, nor iterable.');
-  return chain.asStream(iterator);
+  throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');
 };
 };
 
 
 // default implementation of required stream methods
 // default implementation of required stream methods

+ 1 - 1
tests/test-simple.mjs

@@ -97,7 +97,7 @@ test.asPromise('simple: stream', (t, resolve) => {
 test.asPromise('simple: factory', (t, resolve) => {
 test.asPromise('simple: factory', (t, resolve) => {
   const output = [],
   const output = [],
     c = chain([
     c = chain([
-      [1, 2, 3],
+      fromIterable([1, 2, 3]),
       function* (x) {
       function* (x) {
         yield x * x;
         yield x * x;
         yield x * x * x;
         yield x * x * x;