import * as tsplus_module_1 from "@effect/core/stm/STM/operations/succeedNow";
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";
/**
 * Get the first index of a specific value in the array, bounded above by a
 * specific index, or -1 if it does not occur.
 *
 * @tsplus fluent ets/TArray lastIndexOfFrom
 */

export function lastIndexOfFrom_(self, equivalence) {
  return (a, end) => {
    void 0;

    if (end >= self.chunk.length) {
      return tsplus_module_1.succeedNow(-1);
    }

    return tsplus_module_4.effect(journal => {
      let i = end;
      let found = false;

      while (!found && i >= 0) {
        const value = tsplus_module_3.unsafeGet_(tsplus_module_2.unsafeGet_(self.chunk, i), journal);
        found = equivalence.equals(value, a);
        i = i - 1;
      }

      return found ? i + 1 : -1;
    });
  };
}
/**
 * Get the first index of a specific value in the array, bounded above by a
 * specific index, or -1 if it does not occur.
 *
 * @tsplus static ets/TArray/Aspects lastIndexOfFrom
 */

export const lastIndexOfFrom = equivalence => self => lastIndexOfFrom_(self, equivalence);
//# sourceMappingURL=lastIndexOfFrom.mjs.map