collect_seq

collect_seq

collect_seq(seq)[source]

Collects a sequence of results

If any of the sequence elements is an error, the result is an error which collects all the errors present in the sequence.

If all the sequence elements are values, it returns a sequence of values.

Example

>>> @wrap(ValueError)
... def parse(s: str) -> int:
...    return int(s)
>>> collect_seq([parse("2"), parse("invalid")])
Err1(...)
>>> collect_seq([parse("2"), parse("3")])
[2, 3]
Parameters

seq (Sequence[Union[TypeVar(_Value_co, covariant=True), Err]]) – Sequence of results

Return type

Union[Sequence[TypeVar(_Value_co, covariant=True)], Err]

Returns

An error or a sequence