import { concreteTArray } from "@effect/core/stm/TArray/operations/_internal/InternalTArray" /** * Starting at specified index, get the index of the next entry that matches a * transactional predicate. * * @tsplus static effect/core/stm/TArray.Aspects indexWhereFromSTM * @tsplus pipeable effect/core/stm/TArray indexWhereFromSTM */ export function indexWhereFromSTM( f: (a: A) => STM, from: number ) { return (self: TArray): STM => { if (from < 0) { return STM.succeed(-1) } return forIndex(self, from, f) } } function forIndex( self: TArray, index: number, f: (a: A) => STM ): STM { concreteTArray(self) return index < self.chunk.length ? self.chunk .unsafeGet(index)! .get .flatMap(f) .flatMap((result) => result ? STM.succeed(index) : forIndex(self, index + 1, f)) : STM.succeed(-1) }