Results
Module results
import results
| Module | results |
| Source | results/module-docs.zirr, results/results.zirr |
Helpers for
Result, and for anything carrying@AnyResult.
prelude.Result is the type; results is what you use it with.
Every function takes an @prelude.AnyResult rather than a Result, so a library can define its own Ok/Err union and still pass it here — from converts through the attribute. The pairs are deliberate: map and mapErr transform a value, flatMap and flatMapErr transform it into something that can fail again, and catch and catchTo turn a failure back into a success.
Contents
Functions
all
`results/results.zirr:85`
fn all(ress: [@AnyResult]) -> Result
Combines ress into a single Result: Ok of every value if all are Ok, or Err of every reason if any are Err.
catch
`results/results.zirr:63`
fn catch(r: @AnyResult, handler: fn(Any) -> Any) -> Result
Recovers r’s error by calling handler with its reason and wrapping the result as Ok, or returns r unchanged if it’s already Ok.
catchTo
`results/results.zirr:74`
fn catchTo(r: @AnyResult, default: Any) -> Result
Recovers r’s error by replacing it with Ok(default), or returns r unchanged if it’s already Ok.
flatMap
`results/results.zirr:41`
fn flatMap(r: @AnyResult, transform: fn(Any) -> @AnyResult) -> Result
Returns transform(r’s value) normalized to Result, or r’s error unchanged. Use this instead of map when transform can itself fail.
flatMapErr
`results/results.zirr:52`
fn flatMapErr(r: @AnyResult, transform: fn(Any) -> @AnyResult) -> Result
Returns transform(r’s error reason) normalized to Result, or r’s value unchanged. Use this instead of mapErr to recover with a value that might itself be an error.
from
`results/results.zirr:4`
fn from(r: @AnyResult) -> Result
Normalizes r to Result.
isErr
`results/results.zirr:14`
fn isErr(r: @AnyResult) -> Bool
Returns whether r is Err.
isOk
`results/results.zirr:9`
fn isOk(r: @AnyResult) -> Bool
Returns whether r is Ok.
map
`results/results.zirr:19`
fn map(r: @AnyResult, transform: fn(Any) -> Any) -> Result
Returns a Result with transform applied to r’s value, or r’s error unchanged.
mapErr
`results/results.zirr:30`
fn mapErr(r: @AnyResult, transform: fn(Any) -> Any) -> Result
Returns a Result with transform applied to r’s error reason, or r’s value unchanged.