'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.pushArray = pushArray;
exports.pushSet = pushSet;
exports.setIntersection = setIntersection;
exports.logInGroup = logInGroup;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }

var _reactLibInvariant = require('react/lib/invariant');

var _reactLibInvariant2 = _interopRequireDefault(_reactLibInvariant);

// http://stackoverflow.com/a/4156156/430128

function pushArray(arr, arr2) {
  arr.push.apply(arr, arr2);
}

function pushSet(set1, set2) {
  (0, _reactLibInvariant2['default'])(set2, 'Set to push into must be defined.');
  if (!set1) return;
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = set1[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var value = _step.value;

      set2.add(value);
    }
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator['return']) {
        _iterator['return']();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }
}

function setIntersection(set1, set2) {
  if (!set1 || !set2) return [];
  return [].concat(_toConsumableArray(set1)).filter(function (x) {
    return set2.has(x);
  });
}

function logInGroup(group, f) {
  if (console.group) console.group(group);
  try {
    f();
  } finally {
    if (console.groupEnd) console.groupEnd();
  }
}