Quellcode durchsuchen

Converted Chain the class to chain() the function.

It will help to provide support for standard streams.
Eugene Lazutkin vor 3 Jahren
Ursprung
Commit
7ed01c22b6
12 geänderte Dateien mit 193 neuen und 190 gelöschten Zeilen
  1. 30 27
      src/index.js
  2. 13 13
      tests/test_FromIterable.js
  3. 11 11
      tests/test_demo.js
  4. 3 3
      tests/test_errors.js
  5. 14 14
      tests/test_fold.js
  6. 22 22
      tests/test_fun.js
  7. 24 24
      tests/test_gen.js
  8. 20 20
      tests/test_readWrite.js
  9. 21 21
      tests/test_simple.js
  10. 7 7
      tests/test_skip.js
  11. 14 14
      tests/test_take.js
  12. 14 14
      tests/test_transducers.js

+ 30 - 27
src/index.js

@@ -63,8 +63,8 @@ const groupFunctions = (output, fn, index, fns) => {
 const produceStreams = item => {
   if (Array.isArray(item)) {
     if (!item.length) return null;
-    if (item.length == 1) return item[0] && Chain.asStream(item[0]);
-    return Chain.asStream(Chain.gen(...item));
+    if (item.length == 1) return item[0] && chain.asStream(item[0]);
+    return chain.asStream(chain.gen(...item));
   }
   return item;
 };
@@ -77,13 +77,15 @@ const wrapFunctions = (fn, index, fns) => {
   ) {
     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);
+  return chain.asStream(iterator);
 };
 
+let chain = null; // will be assigned later
+
 class Chain extends Duplex {
   constructor(fns, options) {
     super(Object.assign({}, {writableObjectMode: true, readableObjectMode: true}, options));
@@ -148,30 +150,31 @@ class Chain extends Duplex {
   }
 }
 
-Chain.chain = Chain.make;
 Chain.make.Constructor = Chain;
-Chain.gen = gen;
-Chain.asStream = asStream;
 
-module.exports = Chain;
+chain = Chain.make;
+
+module.exports = chain;
 
 // to keep ESM happy:
-module.exports.none = defs.none;
-module.exports.stop = defs.stop;
-module.exports.Stop = defs.Stop;
-module.exports.finalSymbol = defs.finalSymbol;
-module.exports.manySymbol = defs.manySymbol;
-module.exports.flushSymbol = defs.flushSymbol;
-module.exports.finalValue = defs.finalValue;
-module.exports.many = defs.many;
-module.exports.flushable = defs.flushable;
-module.exports.isFinalValue = defs.isFinalValue;
-module.exports.isMany = defs.isMany;
-module.exports.isFlushable = defs.isFlushable;
-module.exports.getFinalValue = defs.getFinalValue;
-module.exports.getManyValues = defs.getManyValues;
-module.exports.final = defs.final;
-
-module.exports.chain = Chain.make;
-module.exports.gen = gen;
-module.exports.asStream = asStream;
+module.exports.none = chain.none = defs.none;
+module.exports.stop = chain.stop = defs.stop;
+module.exports.Stop = chain.Stop = defs.Stop;
+module.exports.finalSymbol = chain.finalSymbol = defs.finalSymbol;
+module.exports.manySymbol = chain.manySymbol = defs.manySymbol;
+module.exports.flushSymbol = chain.flushSymbol = defs.flushSymbol;
+module.exports.finalValue = chain.finalValue = defs.finalValue;
+module.exports.many = chain.many = defs.many;
+module.exports.flushable = chain.flushable = defs.flushable;
+module.exports.isFinalValue = chain.isFinalValue = defs.isFinalValue;
+module.exports.isMany = chain.isMany = defs.isMany;
+module.exports.isFlushable = chain.isFlushable = defs.isFlushable;
+module.exports.getFinalValue = chain.getFinalValue = defs.getFinalValue;
+module.exports.getManyValues = chain.getManyValues = defs.getManyValues;
+module.exports.final = chain.final = defs.final;
+module.exports.make = chain.make = Chain.make;
+
+module.exports.chain = chain.chain = chain; // for compatibility with 2.x
+module.exports.Chain = chain.Chain = Chain;
+module.exports.gen = chain.gen = gen;
+module.exports.asStream = chain.asStream = asStream;

+ 13 - 13
tests/test_FromIterable.js

@@ -2,7 +2,7 @@
 
 const unit = require('heya-unit');
 
-const Chain = require('../src/index');
+const chain = require('../src/index');
 const {streamToArray, delay} = require('./helpers');
 
 const {fromIterable} = require('../src/utils/FromIterable');
@@ -12,9 +12,9 @@ unit.add(module, [
     const async = t.startAsync('test_FromIterable');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2, 3])'));
       async.done();
     });
@@ -23,9 +23,9 @@ unit.add(module, [
     const async = t.startAsync('test_FromIterableFun');
 
     const output = [],
-      chain = new Chain([fromIterable(() => 0), streamToArray(output)]);
+      c = chain([fromIterable(() => 0), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [0])'));
       async.done();
     });
@@ -34,9 +34,9 @@ unit.add(module, [
     const async = t.startAsync('test_FromIterableAsyncFun');
 
     const output = [],
-      chain = new Chain([fromIterable(delay(() => 0)), streamToArray(output)]);
+      c = chain([fromIterable(delay(() => 0)), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [0])'));
       async.done();
     });
@@ -45,7 +45,7 @@ unit.add(module, [
     const async = t.startAsync('test_FromIterableGen');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable(function*() {
           yield 0;
           yield 1;
@@ -53,7 +53,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [0, 1])'));
       async.done();
     });
@@ -62,7 +62,7 @@ unit.add(module, [
   //   const async = t.startAsync('test_FromIterableAsyncGen');
 
   //   const output = [],
-  //     chain = new Chain([
+  //     c = chain([
   //       fromIterable(async function*() {
   //         yield delay(() => 0)();
   //         yield delay(() => 1)();
@@ -70,7 +70,7 @@ unit.add(module, [
   //       streamToArray(output)
   //     ]);
 
-  //   chain.on('end', () => {
+  //   c.on('end', () => {
   //     eval(t.TEST('t.unify(output, [0, 1])'));
   //     async.done();
   //   });
@@ -79,7 +79,7 @@ unit.add(module, [
     const async = t.startAsync('test_FromIterableNextable');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable((function*() {
           yield 0;
           yield 1;
@@ -87,7 +87,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [0, 1])'));
       async.done();
     });

+ 11 - 11
tests/test_demo.js

@@ -4,7 +4,7 @@ const unit = require('heya-unit');
 
 const {Transform} = require('stream');
 
-const Chain = require('../src/index');
+const chain = require('../src/index');
 const {fromIterable} = require('../src/utils/FromIterable');
 
 const getTotalFromDatabaseByKey = async x =>
@@ -18,11 +18,11 @@ unit.add(module, [
   function test_demo(t) {
     const async = t.startAsync('test_demo');
 
-    const chain = new Chain([
+    const c = chain([
         // transforms a value
         x => x * x,
         // returns several values
-        x => Chain.many([x - 1, x, x + 1]),
+        x => chain.many([x - 1, x, x + 1]),
         // waits for an asynchronous operation
         async x => await getTotalFromDatabaseByKey(x),
         // returns multiple values with a generator
@@ -43,22 +43,22 @@ unit.add(module, [
         })
       ]),
       output = [];
-    chain.on('data', data => output.push(data));
-    chain.on('end', () => {
+    c.on('data', data => output.push(data));
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2])'));
       async.done();
     });
 
-    fromIterable([1, 2, 3]).pipe(chain);
+    fromIterable([1, 2, 3]).pipe(c);
   },
   function test_demoNoGrouping(t) {
     const async = t.startAsync('test_demoNoGrouping');
 
-    const chain = new Chain([
+    const c = chain([
         // transforms a value
         x => x * x,
         // returns several values
-        x => Chain.many([x - 1, x, x + 1]),
+        x => chain.many([x - 1, x, x + 1]),
         // waits for an asynchronous operation
         async x => await getTotalFromDatabaseByKey(x),
         // returns multiple values with a generator
@@ -79,12 +79,12 @@ unit.add(module, [
         })
       ], {noGrouping: true}),
       output = [];
-    chain.on('data', data => output.push(data));
-    chain.on('end', () => {
+    c.on('data', data => output.push(data));
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [2, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2])'));
       async.done();
     });
 
-    fromIterable([1, 2, 3]).pipe(chain);
+    fromIterable([1, 2, 3]).pipe(c);
   }
 ]);

+ 3 - 3
tests/test_errors.js

@@ -2,12 +2,12 @@
 
 const unit = require('heya-unit');
 
-const Chain = require('../src/index');
+const chain = require('../src/index');
 
 unit.add(module, [
   function test_errorsNoStreams(t) {
     try {
-      const chain = new Chain([]);
+      const c = chain([]);
       t.test(false); // shouldn't be here
     } catch (e) {
       eval(t.TEST('e instanceof Error'));
@@ -15,7 +15,7 @@ unit.add(module, [
   },
   function test_errorsWrongStreams(t) {
     try {
-      const chain = new Chain([1]);
+      const c = chain([1]);
       t.test(false); // shouldn't be here
     } catch (e) {
       eval(t.TEST('e instanceof Error'));

+ 14 - 14
tests/test_fold.js

@@ -3,7 +3,7 @@
 const unit = require('heya-unit');
 
 const {streamToArray, delay} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 
 const {fromIterable} = require('../src/utils/FromIterable');
 const fold = require('../src/utils/fold');
@@ -11,20 +11,20 @@ const scan = require('../src/utils/scan');
 const reduce = require('../src/utils/reduce');
 const {reduceStream} = require('../src/utils/ReduceStream');
 
-const {asStream} = Chain;
+const {asStream} = chain;
 
 unit.add(module, [
   function test_fold(t) {
     const async = t.startAsync('test_fold');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         fold((acc, x) => acc + x, 0),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [6])'));
       async.done();
     });
@@ -33,7 +33,7 @@ unit.add(module, [
     const async = t.startAsync('test_foldAsync');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         fold(
           delay((acc, x) => acc + x),
@@ -42,7 +42,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [6])'));
       async.done();
     });
@@ -51,13 +51,13 @@ unit.add(module, [
     const async = t.startAsync('test_foldScan');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         scan((acc, x) => acc + x, 0),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 3, 6])'));
       async.done();
     });
@@ -66,7 +66,7 @@ unit.add(module, [
     const async = t.startAsync('test_foldScanAsync');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         scan(
           delay((acc, x) => acc + x),
@@ -75,7 +75,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 3, 6])'));
       async.done();
     });
@@ -84,13 +84,13 @@ unit.add(module, [
     const async = t.startAsync('test_foldReduce');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         fold((acc, x) => acc + x, 0),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [6])'));
       async.done();
     });
@@ -99,7 +99,7 @@ unit.add(module, [
     const async = t.startAsync('test_foldReduceAsync');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         reduce(
           delay((acc, x) => acc + x),
@@ -108,7 +108,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [6])'));
       async.done();
     });

+ 22 - 22
tests/test_fun.js

@@ -3,21 +3,21 @@
 const unit = require('heya-unit');
 
 const {streamToArray, delay} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 
 const {fromIterable} = require('../src/utils/FromIterable');
 const fun = require('../src/fun');
 
-const {none, finalValue, many} = Chain;
+const {none, finalValue, many} = chain;
 
 unit.add(module, [
   function test_fun(t) {
     const async = t.startAsync('test_fun');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), fun(x => x * x, x => 2 * x + 1), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), fun(x => x * x, x => 2 * x + 1), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -26,13 +26,13 @@ unit.add(module, [
     const async = t.startAsync('test_funFinal');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         fun(x => x * x, x => finalValue(x), x => 2 * x + 1),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -41,9 +41,9 @@ unit.add(module, [
     const async = t.startAsync('test_funNothing');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), fun(x => x * x, () => none, x => 2 * x + 1), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), fun(x => x * x, () => none, x => 2 * x + 1), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [])'));
       async.done();
     });
@@ -52,9 +52,9 @@ unit.add(module, [
     const async = t.startAsync('test_funEmpty');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), x => x * x, fun(), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), x => x * x, fun(), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -63,9 +63,9 @@ unit.add(module, [
     const async = t.startAsync('test_funAsync');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), fun(delay(x => x * x), x => 2 * x + 1), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), fun(delay(x => x * x), x => 2 * x + 1), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -74,7 +74,7 @@ unit.add(module, [
     const async = t.startAsync('test_funGenerator');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         fun(
           x => x * x,
@@ -88,7 +88,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 5, 7, 9, 11, 13, 19, 21, 23])'));
       async.done();
     });
@@ -97,13 +97,13 @@ unit.add(module, [
     const async = t.startAsync('test_funMany');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         fun(x => x * x, x => many([x, x + 1, x + 2]), x => 2 * x + 1),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 5, 7, 9, 11, 13, 19, 21, 23])'));
       async.done();
     });
@@ -112,7 +112,7 @@ unit.add(module, [
     const async = t.startAsync('test_funCombined');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         fun(
           delay(x => -x),
@@ -126,7 +126,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2, 10, 11, 2, 3, 20, 21])'));
       async.done();
     });
@@ -135,7 +135,7 @@ unit.add(module, [
     const async = t.startAsync('test_funCombinedFinal');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         fun(
           delay(x => -x),
@@ -149,7 +149,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, -2, 10, -11, 2, -3, 20, -21])'));
       async.done();
     });
@@ -158,7 +158,7 @@ unit.add(module, [
     const async = t.startAsync('test_funAsFun');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         fun(
           delay(x => -x),
@@ -172,7 +172,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, -2, 10, -11, 2, -3, 20, -21])'));
       async.done();
     });

+ 24 - 24
tests/test_gen.js

@@ -3,17 +3,17 @@
 const unit = require('heya-unit');
 
 const {streamToArray, delay} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 const {fromIterable} = require('../src/utils/FromIterable');
 
-const {none, finalValue, many, gen} = Chain;
+const {none, finalValue, many, gen} = chain;
 
 unit.add(module, [
   function test_gen(t) {
     const async = t.startAsync('test_gen');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
@@ -22,7 +22,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -31,7 +31,7 @@ unit.add(module, [
     const async = t.startAsync('test_genFinal');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
@@ -41,7 +41,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -50,7 +50,7 @@ unit.add(module, [
     const async = t.startAsync('test_compNothing');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
@@ -60,7 +60,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [])'));
       async.done();
     });
@@ -69,9 +69,9 @@ unit.add(module, [
     const async = t.startAsync('test_genEmpty');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), x => x * x, gen(), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), x => x * x, gen(), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -80,7 +80,7 @@ unit.add(module, [
     const async = t.startAsync('test_genAsync');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           delay(x => x * x),
@@ -89,7 +89,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -98,7 +98,7 @@ unit.add(module, [
     const async = t.startAsync('test_genGenerator');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
@@ -112,7 +112,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 5, 7, 9, 11, 13, 19, 21, 23])'));
       async.done();
     });
@@ -121,7 +121,7 @@ unit.add(module, [
     const async = t.startAsync('test_genMany');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
@@ -131,7 +131,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 5, 7, 9, 11, 13, 19, 21, 23])'));
       async.done();
     });
@@ -140,7 +140,7 @@ unit.add(module, [
     const async = t.startAsync('test_genCombined');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         gen(
           delay(x => -x),
@@ -154,7 +154,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2, 10, 11, 2, 3, 20, 21])'));
       async.done();
     });
@@ -163,7 +163,7 @@ unit.add(module, [
     const async = t.startAsync('test_genCombinedFinal');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         gen(
           delay(x => -x),
@@ -177,7 +177,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, -2, 10, -11, 2, -3, 20, -21])'));
       async.done();
     });
@@ -186,7 +186,7 @@ unit.add(module, [
     const async = t.startAsync('test_genSyncIterator');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         gen(
           delay(x => -x),
@@ -200,7 +200,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, -2, 10, -11, 2, -3, 20, -21])'));
       async.done();
     });
@@ -209,7 +209,7 @@ unit.add(module, [
     const async = t.startAsync('test_genAsyncIterator');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2]),
         gen(
           delay(x => -x),
@@ -223,7 +223,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, -2, 10, -11, 2, -3, 20, -21])'));
       async.done();
     });

+ 20 - 20
tests/test_readWrite.js

@@ -3,7 +3,7 @@
 const unit = require('heya-unit');
 
 const {streamToArray} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 const {fromIterable} = require('../src/utils/FromIterable');
 
 unit.add(module, [
@@ -12,12 +12,12 @@ unit.add(module, [
 
     const output1 = [],
       output2 = [],
-      chain = new Chain([fromIterable([1, 2, 3]), x => x * x]);
+      c = chain([fromIterable([1, 2, 3]), x => x * x]);
 
-    chain.pipe(streamToArray(output1));
+    c.pipe(streamToArray(output1));
 
-    chain.on('data', value => output2.push(value));
-    chain.on('end', () => {
+    c.on('data', value => output2.push(value));
+    c.on('end', () => {
       eval(t.TEST('t.unify(output1, [1, 4, 9])'));
       eval(t.TEST('t.unify(output2, [1, 4, 9])'));
       async.done();
@@ -27,11 +27,11 @@ unit.add(module, [
     const async = t.startAsync('test_readWriteWritable');
 
     const output = [],
-      chain = new Chain([x => x * x, streamToArray(output)]);
+      c = chain([x => x * x, streamToArray(output)]);
 
-    fromIterable([1, 2, 3]).pipe(chain);
+    fromIterable([1, 2, 3]).pipe(c);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -40,9 +40,9 @@ unit.add(module, [
     const async = t.startAsync('test_readWriteReadableWritable');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), x => x * x, streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), x => x * x, streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -52,12 +52,12 @@ unit.add(module, [
 
     const output1 = [],
       output2 = [],
-      chain = new Chain([fromIterable([1, 2, 3])]);
+      c = chain([fromIterable([1, 2, 3])]);
 
-    chain.pipe(streamToArray(output1));
+    c.pipe(streamToArray(output1));
 
-    chain.on('data', value => output2.push(value));
-    chain.on('end', () => {
+    c.on('data', value => output2.push(value));
+    c.on('end', () => {
       eval(t.TEST('t.unify(output1, [1, 2, 3])'));
       eval(t.TEST('t.unify(output2, [1, 2, 3])'));
       async.done();
@@ -67,11 +67,11 @@ unit.add(module, [
     const async = t.startAsync('test_readWriteSingleWritable');
 
     const output = [],
-      chain = new Chain([streamToArray(output)]);
+      c = chain([streamToArray(output)]);
 
-    fromIterable([1, 2, 3]).pipe(chain);
+    fromIterable([1, 2, 3]).pipe(c);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2, 3])'));
       async.done();
     });
@@ -81,13 +81,13 @@ unit.add(module, [
 
     const output1 = [],
       output2 = [],
-      chain = new Chain([fromIterable([1, 2, 3]), streamToArray(output1)]);
+      c = chain([fromIterable([1, 2, 3]), streamToArray(output1)]);
 
     fromIterable([4, 5, 6])
-      .pipe(chain)
+      .pipe(c)
       .pipe(streamToArray(output2));
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output1, [1, 2, 3])'));
       eval(t.TEST('t.unify(output2, [])'));
       async.done();

+ 21 - 21
tests/test_simple.js

@@ -4,21 +4,21 @@ const unit = require('heya-unit');
 
 const {Transform} = require('stream');
 const {streamToArray, delay} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 const {fromIterable} = require('../src/utils/FromIterable');
 
 unit.add(module, [
   function test_simpleGeneric(t) {
     const async = t.startAsync('test_simpleGeneric');
 
-    const chain = new Chain([x => x * x]),
+    const c = chain([x => x * x]),
       output1 = [],
       output2 = [];
 
-    fromIterable([1, 2, 3]).pipe(chain).pipe(streamToArray(output1));
+    fromIterable([1, 2, 3]).pipe(c).pipe(streamToArray(output1));
 
-    chain.on('data', value => output2.push(value));
-    chain.on('end', () => {
+    c.on('data', value => output2.push(value));
+    c.on('end', () => {
       eval(t.TEST('t.unify(output1, [1, 4, 9])'));
       eval(t.TEST('t.unify(output2, [1, 4, 9])'));
       async.done();
@@ -28,7 +28,7 @@ unit.add(module, [
     const async = t.startAsync('test_simpleGenerator');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         function* (x) {
           yield x * x;
@@ -38,7 +38,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 1, 2, 4, 8, 4, 9, 27, 6])'));
       async.done();
     });
@@ -47,9 +47,9 @@ unit.add(module, [
     const async = t.startAsync('test_simpleAsync');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), delay(x => x + 1), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), delay(x => x + 1), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [2, 3, 4])'));
       async.done();
     });
@@ -58,13 +58,13 @@ unit.add(module, [
     const async = t.startAsync('test_simpleMany');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
-        x => Chain.many([x * x, x * x * x, 2 * x]),
+        x => chain.many([x * x, x * x * x, 2 * x]),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 1, 2, 4, 8, 4, 9, 27, 6])'));
       async.done();
     });
@@ -73,14 +73,14 @@ unit.add(module, [
     const async = t.startAsync('test_simpleChain');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         x => x * x,
         x => 2 * x + 1,
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -89,7 +89,7 @@ unit.add(module, [
     const async = t.startAsync('test_simpleStream');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         new Transform({
           objectMode: true,
@@ -101,7 +101,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -110,14 +110,14 @@ unit.add(module, [
     const async = t.startAsync('test_simpleChain');
 
     const output = [],
-      chain = Chain.chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         x => x * x,
         x => 2 * x + 1,
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -126,7 +126,7 @@ unit.add(module, [
     const async = t.startAsync('test_simpleIterable');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         [1, 2, 3],
         function* (x) {
           yield x * x;
@@ -136,11 +136,11 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 1, 2, 4, 8, 4, 9, 27, 6])'));
       async.done();
     });
 
-    chain.end(0); // start the chain
+    c.end(0); // start the chain
   }
 ]);

+ 7 - 7
tests/test_skip.js

@@ -3,7 +3,7 @@
 const unit = require('heya-unit');
 
 const {streamToArray, delay} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 
 const {fromIterable} = require('../src/utils/FromIterable');
 const skip = require('../src/utils/skip');
@@ -14,9 +14,9 @@ unit.add(module, [
     const async = t.startAsync('test_skip');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), skip(2), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), skip(2), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 4, 5])'));
       async.done();
     });
@@ -25,9 +25,9 @@ unit.add(module, [
     const async = t.startAsync('test_skipWhile');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), skipWhile(x => x != 3), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), skipWhile(x => x != 3), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 4, 5])'));
       async.done();
     });
@@ -36,9 +36,9 @@ unit.add(module, [
     const async = t.startAsync('test_skipWhileAsync');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), skipWhile(delay(x => x != 3)), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), skipWhile(delay(x => x != 3)), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 4, 5])'));
       async.done();
     });

+ 14 - 14
tests/test_take.js

@@ -3,23 +3,23 @@
 const unit = require('heya-unit');
 
 const {streamToArray, delay} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 
 const {fromIterable} = require('../src/utils/FromIterable');
 const take = require('../src/utils/take');
 const takeWhile = require('../src/utils/takeWhile');
 const takeWithSkip = require('../src/utils/takeWithSkip');
 
-const {stop} = Chain;
+const {stop} = chain;
 
 unit.add(module, [
   function test_take(t) {
     const async = t.startAsync('test_take');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), take(2), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), take(2), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2])'));
       async.done();
     });
@@ -28,9 +28,9 @@ unit.add(module, [
     const async = t.startAsync('test_takeWithSkip');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), takeWithSkip(2, 2), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), takeWithSkip(2, 2), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 4])'));
       async.done();
     });
@@ -39,9 +39,9 @@ unit.add(module, [
     const async = t.startAsync('test_takeWhile');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), takeWhile(x => x != 3), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), takeWhile(x => x != 3), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2])'));
       async.done();
     });
@@ -50,9 +50,9 @@ unit.add(module, [
     const async = t.startAsync('test_takeWhileAsync');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), takeWhile(delay(x => x != 3)), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), takeWhile(delay(x => x != 3)), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2])'));
       async.done();
     });
@@ -61,9 +61,9 @@ unit.add(module, [
     const async = t.startAsync('test_takeStop');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), take(2, stop), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), take(2, stop), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 2])'));
       async.done();
     });
@@ -72,9 +72,9 @@ unit.add(module, [
     const async = t.startAsync('test_takeStopWithSkip');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3, 4, 5]), takeWithSkip(2, 2, stop), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3, 4, 5]), takeWithSkip(2, 2, stop), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 4])'));
       async.done();
     });

+ 14 - 14
tests/test_transducers.js

@@ -3,17 +3,17 @@
 const unit = require('heya-unit');
 
 const {streamToArray} = require('./helpers');
-const Chain = require('../src/index');
+const chain = require('../src/index');
 const {fromIterable} = require('../src/utils/FromIterable');
 
-const {gen} = Chain;
+const {gen} = chain;
 
 unit.add(module, [
   function test_transducers(t) {
     const async = t.startAsync('test_transducers');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
@@ -22,7 +22,7 @@ unit.add(module, [
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });
@@ -31,17 +31,17 @@ unit.add(module, [
     const async = t.startAsync('test_transducersFinal');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
-          x => Chain.finalValue(x),
+          x => chain.finalValue(x),
           x => 2 * x + 1
         ),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -50,17 +50,17 @@ unit.add(module, [
     const async = t.startAsync('test_transducersNothing');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         gen(
           x => x * x,
-          () => Chain.none,
+          () => chain.none,
           x => 2 * x + 1
         ),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [])'));
       async.done();
     });
@@ -69,9 +69,9 @@ unit.add(module, [
     const async = t.startAsync('test_transducersEmpty');
 
     const output = [],
-      chain = new Chain([fromIterable([1, 2, 3]), x => x * x, gen(), streamToArray(output)]);
+      c = chain([fromIterable([1, 2, 3]), x => x * x, gen(), streamToArray(output)]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [1, 4, 9])'));
       async.done();
     });
@@ -80,14 +80,14 @@ unit.add(module, [
     const async = t.startAsync('test_transducersOne');
 
     const output = [],
-      chain = new Chain([
+      c = chain([
         fromIterable([1, 2, 3]),
         x => x * x,
         gen(x => 2 * x + 1),
         streamToArray(output)
       ]);
 
-    chain.on('end', () => {
+    c.on('end', () => {
       eval(t.TEST('t.unify(output, [3, 9, 19])'));
       async.done();
     });