import * as tsplus_module_1 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/unsafeGet";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/List/empty";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/List/prepend";
import * as tsplus_module_5 from "@effect/core/stm/TRef/operations/unsafeSet";
import * as tsplus_module_6 from "@effect/core/stm/STM/operations/effect";
import { concreteTArray } from "@effect/core/stm/TArray/operations/_internal/InternalTArray";
import { concreteTMap } from "@effect/core/stm/TMap/operations/_internal/InternalTMap";
/**
 * Removes bindings matching predicate.
 *
 * @tsplus fluent ets/TMap removeIfDiscard
 */

export function removeIfDiscard_(self, f) {
  void 0;
  return tsplus_module_6.effect(journal => {
    const buckets = tsplus_module_1.unsafeGet_(self.tBuckets, journal);
    void 0;
    const capacity = buckets.chunk.length;
    let i = 0;
    let newSize = 0;

    while (i < capacity) {
      const bucket = tsplus_module_1.unsafeGet_(tsplus_module_2.unsafeGet_(buckets.chunk, i), journal);
      let newBucket = tsplus_module_3.empty();

      for (const pair of bucket) {
        if (!f(pair)) {
          newBucket = tsplus_module_4.prepend_(newBucket, pair);
          newSize += 1;
        }
      }

      tsplus_module_5.unsafeSet_(tsplus_module_2.unsafeGet_(buckets.chunk, i), newBucket, journal);
      i += 1;
    }

    tsplus_module_5.unsafeSet_(self.tSize, newSize, journal);
  });
}
/**
 * Removes bindings matching predicate.
 *
 * @tsplus static ets/TMap/Aspects removeIfDiscard
 */

export const removeIfDiscard = f => self => removeIfDiscard_(self, f);
//# sourceMappingURL=removeIfDiscard.mjs.map