/** * Returns an effect that runs this effect and in case of failure, runs each * of the specified effects in order until one of them succeeds. * * @tsplus static effect/core/io/Effect.Ops firstSuccessOf */ export function firstSuccessOf(effects: Collection>): Effect { return Effect.suspendSucceed(() => { const chunk = Chunk.from(effects) if (chunk.length <= 0) { return Effect.dieSync(new IllegalArgumentException(`received empty collection of effects`)) } const head = chunk.unsafeHead! const tail = chunk.length === 1 ? Chunk.empty>() : chunk.unsafeTail! return tail.reduce(head, (b, a) => b | a) }) }