-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: final implementation of option and result pre-release
- Loading branch information
1 parent
cca9ef1
commit b114d16
Showing
13 changed files
with
1,083 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .option import Option, Some, Nothing,option | ||
from .result import Result, Ok, Err, result | ||
# from .option import Option, Some, Nothing,option | ||
# from .result import Result, Ok, Err, result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import TypeVar, Union | ||
from flusso.option import Option, Some | ||
from flusso.result import Result, Ok, Err | ||
from flusso.types import T, E | ||
|
||
|
||
def flatten(f: Union[Option[T], Result[T, E]]) -> Union[Option[T], Result[T, E]]: | ||
""" | ||
Recursively flattens nested Option and Result containers into a single container. | ||
Args: | ||
f (Union[Option[T], Result[T, E]]): A nested Option or Result container. | ||
Returns: | ||
Union[Option[T], Result[T, E]]: A flattened Option or Result container. | ||
Examples: | ||
>>> flatten(Some(Some(42))) | ||
Some(42) | ||
>>> flatten(Ok(Ok(42))) | ||
Ok(42) | ||
>>> flatten(Ok(Err("error"))) | ||
Ok(Err("error")) | ||
""" | ||
match f: | ||
case Some(inner) if isinstance(inner, Option): | ||
return flatten(inner) | ||
case Ok(inner) if isinstance(inner, Result) and not isinstance(inner, Err): | ||
return flatten(inner) | ||
case _: | ||
return f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.