True Myth / task / inspectRejected
Function: inspectRejected()
Call Signature
inspectRejected<
T,E>(fn): (task) =>Task<T,E>
Auto-curried, standalone function form of Task.inspectRejection Task.prototype.inspectRejection.
This is useful for performing actions like logging, debugging, or other “side effects” external to the wrapped value. (Note: You should never mutate the value in the callback. Doing so will be extremely surprising to callers.) The function is only called if the Task reject, and the original Task is returned unchanged for further chaining.
NOTE
TypeScript type inference is limited with the curried form. You will need to provide explicit type parameters. Alternatively, use the non-curried form to get consistent type inference.
import * as task from 'true-myth/task';
const double = (n: number) => n * 2;
const logError = (error: unknown) => console.error('Got error:', error);
const logAnyError = task.inspect<number, unknown>(logError);
const doubleTask = task.map(double);
// Does not log anything, and returns `Resolved(42)`.
let aResolvingTask = task.resolve<number, string>(42);
logAnyError(doubleTask(logAnyError(aResolvingTask)));
// Logs: "Got error: error"
let aRejectingTask = task.reject<number, string>('error');
logAnyError(doubleTask(logAnyError(aRejectingTask)));Type Parameters
T
T
The type of the value when the Task resolves successfully.
E
E
The type of the rejection reason when the Task rejects.
Parameters
fn
(error) => void
The function to call with the rejection reason (only called on rejection)
Returns
The original Task, unchanged
(
task):Task<T,E>
Parameters
task
Task<T, E>
Returns
Task<T, E>
Call Signature
inspectRejected<
T,E>(fn,task):Task<T,E>
Standalone function form of Task.inspectRejection Task.prototype.inspectRejection.
This is useful for performing actions like logging, debugging, or other “side effects” external to the wrapped value. (Note: You should never mutate the value in the callback. Doing so will be extremely surprising to callers.) The function is only called if the Task reject, and the original Task is returned unchanged for further chaining.
import * as task from 'true-myth/task';
const double = (n: number) => n * 2;
const logError = (error: unknown) => console.error('Got error:', error);
// Does not log anything, and returns `Resolved(42)`.
let aResolvingTask = task.resolve<number, string>(42);
task.inspectRejected(
logError,
task.map(
double,
task.inspectRejected(
logError,
aResolvingTask
)
)
);
// Logs: "Got error: error"
let aRejectingTask = task.reject<number, string>('error');
task.inspectRejected(
logError,
task.map(
double,
task.inspectRejected(
logError,
aRejectingTask
)
)
);Type Parameters
T
T
The type of the value when the Task resolves successfully.
E
E
The type of the rejection reason when the Task rejects.
Parameters
fn
(error) => void
The function to call with the rejection reason (only called on rejection)
task
Task<T, E>
The Task to inspect
Returns
Task<T, E>
The original Task, unchanged