Executes a side effect function on the success value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state.
The input Result or ResultAsync.
The return type of the inspection function.
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.succeed(42), Result.inspect((value) => console.log('Debug:', value)),);// Console output: "Debug: 42"// Result: { type: 'Success', value: 42 } Copy
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.succeed(42), Result.inspect((value) => console.log('Debug:', value)),);// Console output: "Debug: 42"// Result: { type: 'Success', value: 42 }
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.fail('error'), Result.inspect((value) => console.log('Debug:', value)),);// No console output// Result: { type: 'Failure', error: 'error' } Copy
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.fail('error'), Result.inspect((value) => console.log('Debug:', value)),);// No console output// Result: { type: 'Failure', error: 'error' }
pipe - It is recommended to use this function with the pipe function for better readability and composability.
Executes a side effect function on the success value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state.
Type Param: R1
The input Result or ResultAsync.
Type Param: R2
The return type of the inspection function.
Example: Success Case
Example: Failure Case
See
pipe - It is recommended to use this function with the pipe function for better readability and composability.