| 1981 | * @category elements |
| 1982 | */ |
| 1983 | export const firstSuccessOf = <A, E, R>(effects: Iterable<STM<A, E, R>>): STM<A, E, R> => |
| 1984 | suspend<A, E, R>(() => { |
| 1985 | const list = Chunk.fromIterable(effects) |
| 1986 | if (!Chunk.isNonEmpty(list)) { |
| 1987 | return dieSync(() => new Cause.IllegalArgumentException(`Received an empty collection of effects`)) |
| 1988 | } |
| 1989 | return Chunk.reduce( |
| 1990 | Chunk.tailNonEmpty(list), |
| 1991 | Chunk.headNonEmpty(list), |
| 1992 | (left, right) => orElse(left, () => right) |
| 1993 | ) |
| 1994 | }) |
| 1995 | |
| 1996 | /** |
| 1997 | * @category do notation |