Function: inspect()

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

The input Result or ResultAsync.

Type Param

The return type of the inspection function.

Examples

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' }

See

pipe - It is recommended to use this function with the pipe function for better readability and composability.

Call Signature

inspect<R1>(fn): (result) => R1

Defined in: functions/inspect.ts:46

Type Parameters

R1

R1 extends ResultMaybeAsync<any, any>

Parameters

fn

(a) => unknown

Returns

(result): R1

Parameters

result

R1

Returns

R1

Call Signature

inspect<F>(fn): <R1>(result) => R1

Defined in: functions/inspect.ts:47

Type Parameters

F

F extends (a) => unknown

Parameters

fn

F

Returns

<R1>(result): R1

Type Parameters

R1

R1 extends ResultMaybeAsync<Parameters<F>[0], any>

Parameters

result

R1

Returns

R1