flat_map
flat_map¶
- flat_map(f, r)[source]¶
Enables the chaining computations that can error
Example
>>> from math import sqrt >>> @wrap(ValueError) ... def parse(s: str) -> float: ... return float(s) >>> @wrap(ValueError) ... def my_sqrt(f: float) -> float: ... return sqrt(f) >>> flat_map(my_sqrt, parse("2")) 1.414... >>> flat_map(my_sqrt, parse("-1")) Err1(msg='ValueError thrown: math domain error', contexts=[]) >>> flat_map(my_sqrt, parse("invalid")) Err1(msg="ValueError thrown: could not convert string to float: 'invalid'", contexts=[])
- Parameters
- Return type
- Returns
Result parameterized by type _ReturnType
See also