/** * Takes all matching values, or retries until there is at least one. * * @tsplus static effect/core/stm/TMap.Aspects takeSomeSTM * @tsplus pipeable effect/core/stm/TMap takeSomeSTM */ export function takeSomeSTM( pf: (kv: readonly [K, V]) => STM, A> ) { return (self: TMap): STM> => // todo: rewrite to STM> self.findAllSTM((kv) => pf(kv).map((a) => [kv[0], a] as const)).map(Chunk.from).continueOrRetry( (_) => Maybe.fromPredicate(_, (c) => c.size > 0) ).flatMap((both) => self.deleteAll(both.map((_) => _[0])).as(both.map((_) => _[1]))) }