From b8cb7d864c0cc87ff54818c54202d7bc3be21715 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 5 Mar 2023 21:45:02 -0500 Subject: [PATCH] Add drop_none --- emis_funky_funktions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/emis_funky_funktions.py b/emis_funky_funktions.py index 8c8be4b..929d22a 100644 --- a/emis_funky_funktions.py +++ b/emis_funky_funktions.py @@ -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]):