map

map

map(f, r)[source]

Enables a computation on the value of a result

Example

>>> from math import sqrt
>>> @wrap(ValueError)
... def parse(s: str) -> float:
...    return float(s)
>>> @wrap(ValueError)
... def square(f: float) -> float:
...    return f*f
>>> map(square, parse("2"))
4.0
>>> map(square, parse("-1"))
1.0
>>> flat_map(square, parse("invalid"))
Err1(msg="ValueError thrown: could not convert string to float: 'invalid'", contexts=[])
Parameters
  • f (Callable[[TypeVar(_Value_co, covariant=True)], TypeVar(_ReturnType)]) – Function that takes a value of type ._Value_co and returns a value of type ._ReturnType

  • r (Union[TypeVar(_Value_co, covariant=True), Err]) – Result parameterized by type ._Value_co

Return type

Union[TypeVar(_ReturnType), Err]

Returns

Result parameterized by type ._ReturnType

See also

flatMap()