"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.collectWhileEffect_ = exports.collectWhileEffect = void 0;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/empty"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeedNow"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/single"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/map"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/fold"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Maybe/definition"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/append"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/zipWith"));

var _definition2 = /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/definition");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/collection/Chunk/operations/collectWhileEffect.ts";
const collectWhileEffect_ = collectWhileEffect_1;
exports.collectWhileEffect_ = collectWhileEffect_;

/**
 * Transforms all elements of the chunk for as long as the specified partial
 * function is defined.
 *
 * @tsplus fluent Chunk collectWhileEffect
 */
function collectWhileEffect_1(self, f) {
  void 0;

  switch (self._typeId) {
    case _definition2.SingletonTypeId:
      {
        return tsplus_module_5.fold_(f(self.a), () => tsplus_module_2.succeedNow(tsplus_module_1.empty(), fileName_1 + ":18:32"), b => tsplus_module_4.map_(b, tsplus_module_3.single, fileName_1 + ":19:21"));
      }

    case _definition2.ArrTypeId:
      {
        const array = self._arrayLike();

        let dest = tsplus_module_2.succeedNow(tsplus_module_1.empty(), fileName_1 + ":24:59");

        for (let i = 0; i < array.length; i++) {
          const rhs = f(array[i]);

          if (tsplus_module_6.isSome(rhs)) {
            dest = tsplus_module_8.zipWith_(dest, () => rhs.value, (a, b) => tsplus_module_7.append_(a, b), fileName_1 + ":28:30");
          } else {
            return dest;
          }
        }

        return dest;
      }

    default:
      {
        return collectWhileEffect_1(self._materialize(), f);
      }
  }
}
/**
 * Transforms all elements of the chunk for as long as the specified partial
 * function is defined.
 *
 * @tsplus static Chunk/Aspects collectWhileEffect
 */


const collectWhileEffect = f => self => collectWhileEffect_(self, f);

exports.collectWhileEffect = collectWhileEffect;
//# sourceMappingURL=collectWhileEffect.js.map