import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/empty";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/succeedNow";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/single";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_5 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_6 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_7 from "@tsplus/stdlib/collections/Chunk/append";
import * as tsplus_module_8 from "@effect/core/io/Effect/operations/zipWith";
export const collectEffect_ = collectEffect_1;
import { ArrTypeId, concreteChunk, SingletonTypeId } from "@tsplus/stdlib/collections/Chunk/definition";
/**
 * Returns a filtered, mapped subset of the elements of this chunk based on a
 * partial function.
 *
 * @tsplus fluent Chunk collectEffect
 */

function collectEffect_1(self, f, __tsplusTrace) {
  void 0;

  switch (self._typeId) {
    case SingletonTypeId:
      {
        return tsplus_module_5.fold_(f(self.a), () => tsplus_module_2.succeedNow(tsplus_module_1.empty(), __tsplusTrace), b => tsplus_module_4.map_(b, tsplus_module_3.single, __tsplusTrace));
      }

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

        let dest = tsplus_module_2.succeedNow(tsplus_module_1.empty(), __tsplusTrace);

        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), __tsplusTrace);
          }
        }

        return dest;
      }

    default:
      {
        return collectEffect_1(self._materialize(), f, __tsplusTrace);
      }
  }
}
/**
 * Returns a filtered, mapped subset of the elements of this chunk based on a
 * partial function.
 *
 * @tsplus static Chunk/Aspects collectEffect
 */


export const collectEffect = (f, __tsplusTrace) => self => collectEffect_(self, f, __tsplusTrace);
//# sourceMappingURL=collectEffect.mjs.map