tee Functions
These functions allow us to execute side effects based on our result. They are useful for logging and other side effects that we want to execute without changing the result.
Consider the following code for the examples below
tee
If the result is Ok, executes the function on the Ok value. Passes through the input value unchanged.
Function Signature
Examples
Example 1
teeError
If the result is Error, executes the function on the Error value. Passes through the input value unchanged.
Function Signature
Examples
Example 1
teeIf
If the result is Ok and the predicate returns true for the wrapped value, executes the function on the Ok value. Passes through the input value unchanged.
Function Signature
Examples
Example 1
Since predicate condition is met, the log function is executed.
Example 2
Since predicate condition is not met, the log function is not executed.
teeErrorIf
If the result is Error and the predicate returns true for the wrapped value, executes the function on the Error value. Passes through the input value unchanged.
Function Signature
Examples
Example 1
Since predicate condition is met, the log function is executed.
Example 2
Since predicate condition is not met, the log function is not executed.
Last updated