import * as tsplus_module_1 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/unsafeGet";
import * as tsplus_module_3 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_4 from "@effect/core/stm/STM/operations/effect";
import { concreteTArray } from "@effect/core/stm/TArray/operations/_internal/InternalTArray";
/**
 * Find the last element in the array matching a predicate.
 *
 * @tsplus fluent ets/TArray findLast
 */

export function findLast_(self, f) {
  return tsplus_module_4.effect(journal => {
    void 0;
    let i = self.chunk.length - 1;
    let res = tsplus_module_1.emptyOf();

    while (tsplus_module_1.isNone(res) && i >= 0) {
      const a = tsplus_module_3.unsafeGet_(tsplus_module_2.unsafeGet_(self.chunk, i), journal);

      if (f(a)) {
        res = tsplus_module_1.some(a);
      }

      i = i - 1;
    }

    return res;
  });
}
/**
 * Find the last element in the array matching a predicate.
 *
 * @tsplus static ets/TArray/Aspects findLast
 */

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