Hyperlinkv0.8.0-beta.28

Cause

Cause.combineconsteffect/Cause.ts:712
<E2>(that: Cause<E2>): <E>(self: Cause<E>) => Cause<E | E2>
<E, E2>(self: Cause<E>, that: Cause<E2>): Cause<E | E2>

Merges two causes into a single cause whose reasons array is the union of both inputs (de-duplicated by value equality).

When to use

Use to merge independent causes into one structured failure value.

Details

  • Combining with empty returns the other cause unchanged.
  • If the result is structurally equal to self, self is returned (referential shortcut).

Example (Combining two causes)

import { Cause } from "effect"

const cause1 = Cause.fail("error1")
const cause2 = Cause.fail("error2")
const combined = Cause.combine(cause1, cause2)
console.log(combined.reasons.length) // 2
Source effect/Cause.ts:7124 lines
export const combine: {
  <E2>(that: Cause<E2>): <E>(self: Cause<E>) => Cause<E | E2>
  <E, E2>(self: Cause<E>, that: Cause<E2>): Cause<E | E2>
} = effect.causeCombine