Executes a side effect function on the error 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.fail('error'), Result.inspectError((error) => console.log('Debug error:', error)),);// Console output: "Debug error: error"// Result: { type: 'Failure', error: 'error' } Copy
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.fail('error'), Result.inspectError((error) => console.log('Debug error:', error)),);// Console output: "Debug error: error"// Result: { type: 'Failure', error: 'error' }
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.succeed(42), Result.inspectError((error) => console.log('Debug error:', error)),);// No console output// Result: { type: 'Success', value: 42 } Copy
import { Result } from '@praha/byethrow';const result = Result.pipe( Result.succeed(42), Result.inspectError((error) => console.log('Debug error:', error)),);// No console output// Result: { type: 'Success', value: 42 }
pipe - It is recommended to use this function with the pipe function for better readability and composability.
Executes a side effect function on the error 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: Failure Case
Example: Success Case
See
pipe - It is recommended to use this function with the pipe function for better readability and composability.