Merge branch 'main' into the-lab

This commit is contained in:
Emi Simpson 2023-02-12 11:09:06 -05:00
commit 0d728f62bd
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -707,7 +707,7 @@ def unwrap_r(r: Result[A, Any]) -> A:
return val
case Err(e):
raise AssertionError(f'Tried to unwrap an error: ', e)
def sequence(s: Sequence[Result[A, B]]) -> Result[Iterator[A], B]:
def sequence(s: Sequence[Result[A, B]]) -> Result[Sequence[A], B]:
"""
Convert a list of results into a result of a list.
@ -716,14 +716,14 @@ def sequence(s: Sequence[Result[A, B]]) -> Result[Iterator[A], B]:
errors, proccessing of the sequence is immediately stopped, and the first error
encountered is returned.
>>> map_res(list, sequence([Ok(1), Ok(2), Ok(3)]))
>>> sequence([Ok(1), Ok(2), Ok(3)])
Ok([1, 2, 3])
>>> sequence([Ok(1), Err('Oops!'), Err('Aw man!')])
Err('Oops!')
"""
if all(s):
return Ok(map(unwrap_r, s))
return Ok(list(map(unwrap_r, s)))
else:
o = next(filter(not_, s))
assert isinstance(o, Err)