Python-flavored Option[T] and Result[T, E], empowered with static typing.
Option[T]=Some[T]|Null- support for
matchstatement:match option: case Some(value): print(value) case Null.null: ...
Result[T, E]=Ok[T]|Err[E]- support for
matchstatement:match result: case Ok(value): print(value) case Err(err): print(err)
from_noneturnsT | NoneintoOption[T]:data: dict[str, int] = {} value: Option[int] = from_none(data.get("foo"))
try_optionturns functions thatreturn Torraise EintoOption[T]try_resultturns functions thatreturn Torraise EintoResult[T, E]CatchResultcaptures the result (or exception) of a block of code intoResult:with CatchResult(OSError) as catch: catch @= await client.get("foo") catch.result # Ok(data) | Err(OSError(...))
collect_optionscollectsIterable[Option[T]]intoSome[list[T]]iff all options areSome, elseNullcollect_resultscollectsIterable[Result[T, E]]intoOk[list[T]]iff all results areOk, else the firstErr[E]