Add drop_none
This commit is contained in:
parent
db2f9710dd
commit
b8cb7d864c
|
@ -589,6 +589,15 @@ def unwrap_opt(r: Option[A]) -> A:
|
||||||
case None:
|
case None:
|
||||||
raise AssertionError('Tried to unwrap a None value')
|
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!
|
# Results!
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Ok(Generic[A, B]):
|
class Ok(Generic[A, B]):
|
||||||
|
|
Loading…
Reference in a new issue