'use strict';

const h = require('highland');

class Pipeline {
  constructor() {
    this._input = h();
    this._transforms = [];
  }

  apply(obj) {

    /**
     * If we have a curried function then save it as is:
     */

    if (typeof obj === 'function') {
      this._transforms.push(obj);
    }

    /**
     * Otherwise, we let the object itself tell us what to
     * save:
     */

    else {
      this._transforms.push(obj.apply());
    }

    return this;
  }

  run(cb) {
    /**
     * The transforms list is a set of curried functions; use them to
     * a Highland pipeline:
     */

    let pipeline = s => this._transforms.reduce((stream, fn) => fn(stream), s);

    h()
    .through(pipeline)
    .done(cb);
  }
};

module.exports = Pipeline;

@@ -479,14 +479,21 @@
 run(
-cb
+finished
 ) %7B%0A
+%0A
     
@@ -729,11 +729,76 @@
 one(
-cb)
+() =%3E %7B%0A      if (finished) %7B%0A        finished()%0A      %7D%0A    %7D)%0A    
 ;%0A  

check if there is actually a finished callback in Pipeline.run()