Add drop_none

This commit is contained in:
Emi Simpson 2023-03-05 21:45:02 -05:00
parent db2f9710dd
commit b8cb7d864c
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -589,6 +589,15 @@ def unwrap_opt(r: Option[A]) -> A:
case None:
raise AssertionError('Tried to unwrap a None value')
def drop_none(l: Iterable[Option[A]]) -> Sequence[A]:
"""
Drop every instance of `None` from a list, unwraping the rest
>>> drop_none([Some(1), None, Some(2), None, Some(3)])
[1, 2, 3]
"""
return [o.val for o in l if o is not None]
# Results!
@dataclass(frozen=True)
class Ok(Generic[A, B]):