text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.asEffect = undefined;
  
  var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  
  exports.take = take;
  exports.takem = takem;
  exports.put = put;
  exports.race = race;
  exports.call = call;
  exports.apply = apply;
  exports.cps = cps;
  exports.fork = fork;
  exports.spawn = spawn;
  exports.join = join;
  exports.cancel = cancel;
  exports.select = select;
  exports.actionChannel = actionChannel;
  exports.cancelled = cancelled;
  
  var _utils = require('./utils');
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  var IO = (0, _utils.sym)('IO');
  var TAKE = 'TAKE';
  var PUT = 'PUT';
  var RACE = 'RACE';
  var CALL = 'CALL';
  var CPS = 'CPS';
  var FORK = 'FORK';
  var JOIN = 'JOIN';
  var CANCEL = 'CANCEL';
  var SELECT = 'SELECT';
  var ACTION_CHANNEL = 'ACTION_CHANNEL';
  var CANCELLED = 'CANCELLED';
  
  var effect = function effect(type, payload) {
    var _ref;
  
    return _ref = {}, _defineProperty(_ref, IO, true), _defineProperty(_ref, type, payload), _ref;
  };
  
  function take(channel, pattern) {
    if (arguments.length >= 2) {
      (0, _utils.check)(channel, _utils.is.notUndef, 'take(channel, pattern): channel is undefined');
      (0, _utils.check)(channel, _utils.is.take, 'take(channel, pattern): argument ' + channel + ' is not a valid channel (channel argument must have a take method)');
      (0, _utils.check)(pattern, _utils.is.notUndef, 'take(channel, pattern): pattern is undefined');
      (0, _utils.check)(pattern, _utils.is.pattern, 'take(channel, pattern): argument ' + pattern + ' is not a valid pattern (pattern must be String | Function: a => boolean | Array<String>)');
    } else if (arguments.length === 1) {
      (0, _utils.check)(channel, _utils.is.notUndef, 'take(patternOrChannel): undefined argument');
      if (!_utils.is.take(channel)) {
        if (_utils.is.pattern(channel)) {
          pattern = channel;
          channel = null;
        } else {
          throw new Error('take(patternOrChannel): argument ' + channel + ' is not valid channel or a valid pattern');
        }
      } else {
        pattern = '*';
      }
    } else {
      pattern = '*';
    }
  
    return effect(TAKE, { channel: channel, pattern: pattern });
  }
  
  function takem() {
    var eff = take.apply(undefined, arguments);
    eff[TAKE].maybe = true;
    return eff;
  }
  
  function put(channel, action) {
    if (arguments.length > 1) {
      (0, _utils.check)(channel, _utils.is.notUndef, 'put(channel, action): argument channel is undefined');
      (0, _utils.check)(channel, _utils.is.put, 'put(channel, action): argument ' + channel + ' is not a valid channel (channel argument must have a put method)');
      (0, _utils.check)(action, _utils.is.notUndef, 'put(channel, action): argument action is undefined');
    } else {
      (0, _utils.check)(channel, _utils.is.notUndef, 'put(action): argument action is undefined');
      action = channel;
      channel = null;
    }
    return effect(PUT, { channel: channel, action: action });
  }
  
  function race(effects) {
    return effect(RACE, effects);
  }
  
  function getFnCallDesc(meth, fn, args) {
    (0, _utils.check)(fn, _utils.is.notUndef, meth + ': argument fn is undefined');
  
    var context = null;
    if (_utils.is.array(fn)) {
      var _fn = fn;
  
      var _fn2 = _slicedToArray(_fn, 2);
  
      context = _fn2[0];
      fn = _fn2[1];
    } else if (fn.fn) {
      var _fn3 = fn;
      context = _fn3.context;
      fn = _fn3.fn;
    }
    (0, _utils.check)(fn, _utils.is.func, meth + ': argument ' + fn + ' is not a function');
  
    return { context: context, fn: fn, args: args };
  }
  
  function call(fn) {
    for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
      args[_key - 1] = arguments[_key];
    }
  
    return effect(CALL, getFnCallDesc('call', fn, args));
  }
  
  function apply(context, fn) {
    var args = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
  
    return effect(CALL, getFnCallDesc('apply', { context: context, fn: fn }, args));
  }
  
  function cps(fn) {
    for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
      args[_key2 - 1] = arguments[_key2];
    }
  
    return effect(CPS, getFnCallDesc('cps', fn, args));
  }
  
  function fork(fn) {
    for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
      args[_key3 - 1] = arguments[_key3];
    }
  
    return effect(FORK, getFnCallDesc('fork', fn, args));
  }
  
  function spawn(fn) {
    for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
      args[_key4 - 1] = arguments[_key4];
    }
  
    var eff = fork.apply(undefined, [fn].concat(args));
    eff[FORK].detached = true;
    return eff;
  }
  
  var isForkedTask = function isForkedTask(task) {
    return task[_utils.TASK];
  };
  
  function join(task) {
    (0, _utils.check)(task, _utils.is.notUndef, 'join(task): argument task is undefined');
    if (!isForkedTask(task)) {
      throw new Error('join(task): argument ' + task + ' is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)');
    }
  
    return effect(JOIN, task);
  }
  
  function cancel(task) {
    (0, _utils.check)(task, _utils.is.notUndef, 'cancel(task): argument task is undefined');
    if (!isForkedTask(task)) {
      throw new Error('cancel(task): argument ' + task + ' is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)');
    }
  
    return effect(CANCEL, task);
  }
  
  function select(selector) {
    for (var _len5 = arguments.length, args = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
      args[_key5 - 1] = arguments[_key5];
    }
  
    if (arguments.length === 0) {
      selector = _utils.ident;
    } else {
      (0, _utils.check)(select, _utils.is.notUndef, 'select(selector,[...]): argument selector is undefined');
      (0, _utils.check)(selector, _utils.is.func, 'select(selector,[...]): argument ' + selector + ' is not a function');
    }
    return effect(SELECT, { selector: selector, args: args });
  }
  
  /**
    channel(pattern, [buffer])    => creates an event channel for store actions
  **/
  function actionChannel(pattern, buffer) {
    (0, _utils.check)(pattern, _utils.is.notUndef, 'actionChannel(pattern,...): argument pattern is undefined');
    if (arguments.length > 1) {
      (0, _utils.check)(buffer, _utils.is.notUndef, 'actionChannel(pattern, buffer): argument buffer is undefined');
      (0, _utils.check)(buffer, _utils.is.notUndef, 'actionChannel(pattern, buffer): argument ' + buffer + ' is not a valid buffer');
    }
    return effect(ACTION_CHANNEL, { pattern: pattern, buffer: buffer });
  }
  
  function cancelled() {
    return effect(CANCELLED, {});
  }
  
  var asEffect = exports.asEffect = {
    take: function take(effect) {
      return effect && effect[IO] && effect[TAKE];
    },
    put: function put(effect) {
      return effect && effect[IO] && effect[PUT];
    },
    race: function race(effect) {
      return effect && effect[IO] && effect[RACE];
    },
    call: function call(effect) {
      return effect && effect[IO] && effect[CALL];
    },
    cps: function cps(effect) {
      return effect && effect[IO] && effect[CPS];
    },
    fork: function fork(effect) {
      return effect && effect[IO] && effect[FORK];
    },
    join: function join(effect) {
      return effect && effect[IO] && effect[JOIN];
    },
    cancel: function cancel(effect) {
      return effect && effect[IO] && effect[CANCEL];
    },
    select: function select(effect) {
      return effect && effect[IO] && effect[SELECT];
    },
    actionChannel: function actionChannel(effect) {
      return effect && effect[IO] && effect[ACTION_CHANNEL];
    },
    cancelled: function cancelled(effect) {
      return effect && effect[IO] && effect[CANCELLED];
    }
  };