Skip to main content
Module

x/domain_functions/src/domain-functions.ts

Types and functions to make composition easy and safe
Latest
import * as domainFunctions from "https://deno.land/x/domain_functions@v3.0.0/src/domain-functions.ts";

Functions

Creates a single domain function out of multiple domain functions. It will pass the same input and environment to each provided function. The functions will run in parallel. If all constituent functions are successful, The data field will be a tuple containing each function's output.

Use it to add conditional logic to your domain functions' compositions. It receives a domain function and a predicate function that should return the next domain function to be executed based on the previous domain function's output, like pipe. If the predicate returns null the result of the previous domain function will be returned and it won't be piped.

Receives a Record of domain functions, runs them all in parallel and preserves the shape of this record for the data property in successful results.

Receives a Record of domain functions, runs them all in sequence like pipe but preserves the shape of that record for the data property in successful results. It will pass the same environment to all given functions, and it will pass the output of a function as the next function's input in the given order.

Creates a composite domain function that will return the result of the first successful constituent domain function. It is important to notice that all constituent domain functions will be executed in parallel, so be mindful of the side effects.

It can be used to call a domain function from another domain function. It will return the output of the given domain function if it was successfull, otherwise it will throw a ResultError that will bubble up to the parent function. Also good to use it in successfull test cases.

It takes a domain function and a predicate to apply a transformation over the result.data of that function. It only runs if the function was successfull. When the given domain function fails, its error is returned wihout changes.

Creates a single domain function that will apply a transformation over the ErrorResult of a failed DomainFunction. When the given domain function succeeds, its result is returned without changes.

NOTE : Try to use collect instead wherever possible since it is much safer. merge can create domain functions that will always fail in run-time or even overwrite data from successful constituent functions application. The collect function does not have these issues and serves a similar purpose.

Creates a single domain function out of a chain of multiple domain functions. It will pass the same environment to all given functions, and it will pass the output of a function as the next function's input in left-to-right order. The resulting data will be the output of the rightmost function.

Works like pipe but it will collect the output of every function in a tuple, similar to all.

Whenever you need to intercept inputs and a domain function result without changing them you can use this function. The most common use case is to log failures to the console or to an external service.