(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.contra = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = Infinity;

},{}],2:[function(require,module,exports){
module.exports = 1;

},{}],3:[function(require,module,exports){
'use strict';

var _map = require('./_map');

module.exports = function each (concurrency) {
  return _map(concurrency, then);
  function then (collection, done) {
    return function mask (err) {
      done(err); // only return the error, no more arguments
    };
  }
};

},{"./_map":5}],4:[function(require,module,exports){
'use strict';

var a = require('./a');
var _map = require('./_map');

module.exports = function filter (concurrency) {
  return _map(concurrency, then);
  function then (collection, done) {
    return function filter (err, results) {
      function exists (item, key) {
        return !!results[key];
      }
      function ofilter () {
        var filtered = {};
        Object.keys(collection).forEach(function omapper (key) {
          if (exists(null, key)) { filtered[key] = collection[key]; }
        });
        return filtered;
      }
      if (err) { done(err); return; }
      done(null, a(results) ? collection.filter(exists) : ofilter());
    };
  }
};

},{"./_map":5,"./a":6}],5:[function(require,module,exports){
'use strict';

var a = require('./a');
var once = require('./once');
var concurrent = require('./concurrent');
var CONCURRENTLY = require('./CONCURRENTLY');
var SERIAL = require('./SERIAL');

module.exports = function _map (cap, then, attached) {
  function api (collection, concurrency, iterator, done) {
    var args = arguments;
    if (args.length === 2) { iterator = concurrency; concurrency = CONCURRENTLY; }
    if (args.length === 3 && typeof concurrency !== 'number') { done = iterator; iterator = concurrency; concurrency = CONCURRENTLY; }
    var keys = Object.keys(collection);
    var tasks = a(collection) ? [] : {};
    keys.forEach(function insert (key) {
      tasks[key] = function iterate (cb) {
        if (iterator.length === 3) {
          iterator(collection[key], key, cb);
        } else {
          iterator(collection[key], cb);
        }
      };
    });
    concurrent(tasks, cap || concurrency, then ? then(collection, once(done)) : done);
  }
  if (!attached) { api.series = _map(SERIAL, then, true); }
  return api;
};

},{"./CONCURRENTLY":1,"./SERIAL":2,"./a":6,"./concurrent":7,"./once":19}],6:[function(require,module,exports){
'use strict';

module.exports = function a (o) { return Object.prototype.toString.call(o) === '[object Array]'; };

},{}],7:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var a = require('./a');
var once = require('./once');
var queue = require('./queue');
var errored = require('./errored');
var debounce = require('./debounce');
var CONCURRENTLY = require('./CONCURRENTLY');

module.exports = function concurrent (tasks, concurrency, done) {
  if (typeof concurrency === 'function') { done = concurrency; concurrency = CONCURRENTLY; }
  var d = once(done);
  var q = queue(worker, concurrency);
  var keys = Object.keys(tasks);
  var results = a(tasks) ? [] : {};
  q.unshift(keys);
  q.on('drain', function completed () { d(null, results); });
  function worker (key, next) {
    debounce(tasks[key], [proceed]);
    function proceed () {
      var args = atoa(arguments);
      if (errored(args, d)) { return; }
      results[key] = args.shift();
      next();
    }
  }
};

},{"./CONCURRENTLY":1,"./a":6,"./debounce":10,"./errored":13,"./once":19,"./queue":20,"atoa":16}],8:[function(require,module,exports){
'use strict';

module.exports = {
  curry: require('./curry'),
  concurrent: require('./concurrent'),
  series: require('./series'),
  waterfall: require('./waterfall'),
  each: require('./each'),
  map: require('./map'),
  filter: require('./filter'),
  queue: require('./queue'),
  emitter: require('./emitter')
};

},{"./concurrent":7,"./curry":9,"./each":11,"./emitter":12,"./filter":14,"./map":15,"./queue":20,"./series":21,"./waterfall":22}],9:[function(require,module,exports){
'use strict';

var atoa = require('atoa');

module.exports = function curry () {
  var args = atoa(arguments);
  var method = args.shift();
  return function curried () {
    var more = atoa(arguments);
    method.apply(method, args.concat(more));
  };
};

},{"atoa":16}],10:[function(require,module,exports){
'use strict';

var ticky = require('ticky');

module.exports = function debounce (fn, args, ctx) {
  if (!fn) { return; }
  ticky(function run () {
    fn.apply(ctx || null, args || []);
  });
};

},{"ticky":17}],11:[function(require,module,exports){
'use strict';

module.exports = require('./_each')();

},{"./_each":3}],12:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var debounce = require('./debounce');

module.exports = function emitter (thing, options) {
  var opts = options || {};
  var evt = {};
  if (thing === undefined) { thing = {}; }
  thing.on = function (type, fn) {
    if (!evt[type]) {
      evt[type] = [fn];
    } else {
      evt[type].push(fn);
    }
    return thing;
  };
  thing.once = function (type, fn) {
    fn._once = true; // thing.off(fn) still works!
    thing.on(type, fn);
    return thing;
  };
  thing.off = function (type, fn) {
    var c = arguments.length;
    if (c === 1) {
      delete evt[type];
    } else if (c === 0) {
      evt = {};
    } else {
      var et = evt[type];
      if (!et) { return thing; }
      et.splice(et.indexOf(fn), 1);
    }
    return thing;
  };
  thing.emit = function () {
    var args = atoa(arguments);
    return thing.emitterSnapshot(args.shift()).apply(this, args);
  };
  thing.emitterSnapshot = function (type) {
    var et = (evt[type] || []).slice(0);
    return function () {
      var args = atoa(arguments);
      var ctx = this || thing;
      if (type === 'error' && opts.throws !== false && !et.length) { throw args.length === 1 ? args[0] : args; }
      et.forEach(function emitter (listen) {
        if (opts.async) { debounce(listen, args, ctx); } else { listen.apply(ctx, args); }
        if (listen._once) { thing.off(type, listen); }
      });
      return thing;
    };
  };
  return thing;
};

},{"./debounce":10,"atoa":16}],13:[function(require,module,exports){
'use strict';

var debounce = require('./debounce');

module.exports = function errored (args, done, disposable) {
  var err = args.shift();
  if (err) { if (disposable) { disposable.discard(); } debounce(done, [err]); return true; }
};

},{"./debounce":10}],14:[function(require,module,exports){
'use strict';

module.exports = require('./_filter')();

},{"./_filter":4}],15:[function(require,module,exports){
'use strict';

module.exports = require('./_map')();

},{"./_map":5}],16:[function(require,module,exports){
module.exports = function atoa (a, n) { return Array.prototype.slice.call(a, n); }

},{}],17:[function(require,module,exports){
var si = typeof setImmediate === 'function', tick;
if (si) {
  tick = function (fn) { setImmediate(fn); };
} else {
  tick = function (fn) { setTimeout(fn, 0); };
}

module.exports = tick;
},{}],18:[function(require,module,exports){
'use strict';

module.exports = function noop () {};

},{}],19:[function(require,module,exports){
'use strict';

var noop = require('./noop');

module.exports = function once (fn) {
  var disposed;
  function disposable () {
    if (disposed) { return; }
    disposed = true;
    (fn || noop).apply(null, arguments);
  }
  disposable.discard = function () { disposed = true; };
  return disposable;
};

},{"./noop":18}],20:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var a = require('./a');
var once = require('./once');
var emitter = require('./emitter');
var debounce = require('./debounce');

module.exports = function queue (worker, concurrency) {
  var q = [], load = 0, max = concurrency || 1, paused;
  var qq = emitter({
    push: manipulate.bind(null, 'push'),
    unshift: manipulate.bind(null, 'unshift'),
    pause: function pause () { paused = true; },
    resume: function resume () { paused = false; debounce(labor); },
    pending: q
  });
  if (Object.defineProperty && !Object.definePropertyPartial) {
    Object.defineProperty(qq, 'length', { get: function getter () { return q.length; } });
  }
  function manipulate (how, task, done) {
    var tasks = a(task) ? task : [task];
    tasks.forEach(function insert (t) { q[how]({ t: t, done: done }); });
    debounce(labor);
  }
  function labor () {
    if (paused || load >= max) { return; }
    if (!q.length) { if (load === 0) { qq.emit('drain'); } return; }
    load++;
    var job = q.pop();
    worker(job.t, once(complete.bind(null, job)));
    debounce(labor);
  }
  function complete (job) {
    load--;
    debounce(job.done, atoa(arguments, 1));
    debounce(labor);
  }
  return qq;
};

},{"./a":6,"./debounce":10,"./emitter":12,"./once":19,"atoa":16}],21:[function(require,module,exports){
'use strict';

var concurrent = require('./concurrent');
var SERIAL = require('./SERIAL');

module.exports = function series (tasks, done) {
  concurrent(tasks, SERIAL, done);
};

},{"./SERIAL":2,"./concurrent":7}],22:[function(require,module,exports){
'use strict';

var atoa = require('atoa');
var once = require('./once');
var errored = require('./errored');
var debounce = require('./debounce');

module.exports = function waterfall (steps, done) {
  var d = once(done);
  function next () {
    var args = atoa(arguments);
    var step = steps.shift();
    if (step) {
      if (errored(args, d)) { return; }
      args.push(once(next));
      debounce(step, args);
    } else {
      debounce(d, arguments);
    }
  }
  next();
};

},{"./debounce":10,"./errored":13,"./once":19,"atoa":16}]},{},[8])(8)
});
//# sourceMappingURL=data:application/json;charset:utf-8;base64,[encoded data, 14772 characters]
