Skip to content

Commit 379159f

Browse files
committed
feat: add is_err_and method
1 parent e81d48f commit 379159f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ResultContainer/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,11 @@ class Result:
721721
otherwise False.
722722
- If function call fails, then raises exception.
723723
724+
is_Err_and(bool_err_func, *args, **kwargs):
725+
True if Err(e) variant and bool_err_func(e, *args, **kwargs) returns True,
726+
otherwise False.
727+
- If function call fails, then raises exception.
728+
724729
apply(ok_func, *args, **kwargs):
725730
Maps a function to the Result to return a new Result.
726731
For the Ok(value) variant, returns `Ok(ok_func(value, *args, **kwargs))`.
@@ -1047,6 +1052,9 @@ def setitem(self, key, value, error_raises_exception=False):
10471052
def is_Ok_and(self, bool_ok_func, *args, **kwargs) -> bool:
10481053
return self._success and bool_ok_func(self._val, *args, **kwargs)
10491054

1055+
def is_Err_and(self, bool_err_func, *args, **kwargs) -> bool:
1056+
return not self._success and bool_err_func(self._val, *args, **kwargs)
1057+
10501058
def apply(self, ok_func, *args, **kwargs):
10511059
if self._success:
10521060
try:

0 commit comments

Comments
 (0)