inspectErr method

  1. @override
Result<T, E> inspectErr(
  1. void f(
    1. E error
    )
)
override

Calls the provided closure with the contained error (if Err).

Examples

Result<int, String> parseToInt(String value) {
  try {
    return Ok(int.parse(value));
  } catch (_) {
    return Err(value);
  }
}
Result<int, String> x = parseToInt('four')
  .inspectErr((val) => print("'$val' could not be parsed into an integer")) // prints "'$four' could not be parsed into an integer"

Implementation

@override
Result<T, E> inspectErr(void Function(E error) f) {
  f(e);

  return this;
}