inspect method

Result<T, E> inspect(
  1. void fn(
    1. T
    )
)

Calls the provided function with the contained value if this Result is Ok.

Result<int, String> foo = Ok(1);

int bar = foo
  .map((value) => value + 2)
  .inspect((value) => print(value)) // prints: 3
  .unwrap();

print(bar); // prints: 3

See also: Rust: Result::inspect()

Implementation

Result<T, E> inspect(void Function(T) fn) {
	if (this case Ok(:T v)) {
		fn(v);
	}

	return this;
}