inspect method

Option<T> inspect(
  1. void fn(
    1. T
    )
)

Calls the provided function with the contained value if this Option is Some.

Returns this Option.

Option<int> foo = Some(1);

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

print(bar); // prints: 3

See also: Rust: Option::inspect()

Implementation

Option<T> inspect(void Function(T) fn) {
	if (this case Some(:T v)) {
		fn(v);
	}

	return this;
}