Skip to main content
Module

x/domain_functions/src/index.ts>cf.mapError

Decouple your business logic from your framework. With first-class type inference from end to end.
Go to Latest
function cf.mapError
import { cf } from "https://deno.land/x/domain_functions@v2.6.0/src/index.ts";
const { mapError } = cf;

Creates a new function that will apply a transformation over a resulting Failure from the given function. When the given function succeeds, its result is returned without changes.

Examples

import { cf as C } from 'domain-functions'

const increment = C.composable(({ id }: { id: number }) => id + 1) const incrementWithErrorSummary = C.mapError(increment, (result) => ({ errors: [{ message: 'Errors count: ' + result.errors.length }], }))

Parameters

fn: T
mapper: (err: Omit<Failure, "success">) => Omit<Failure, "success">