# Fx.merge

Merges two Fx streams into a single Fx that emits values from both streams
concurrently. Order of emission is non-deterministic.

**Completion:** The merged stream completes when **both** input streams have
completed.

**Failures:** Every failure Cause is delivered to the downstream Sink. Delivery does not make
`Fx.run` fail, so `merge` does not itself cancel the sibling; a terminal observer may choose to.

## Signatures

```ts
export declare const merge: {
    <A2, E2, R2>(that: Fx<A2, E2, R2>): <A, E, R>(self: Fx<A, E, R>) => Fx<A | A2, E | E2, R | R2>;
    <A, E, R, A2, E2, R2>(self: Fx<A, E, R>, that: Fx<A2, E2, R2>): Fx<A | A2, E | E2, R | R2>;
};
```

## Why

`merge` preserves both producers instead of imposing a pairing relationship. Each input value is
emitted once as soon as its source pushes it, so inter-source ordering is intentionally undefined.

## Ownership and lifetime

Both runs are children of the consumer and completion waits for both. Downstream interruption
cancels the remaining runs. A source Cause is only sent to `sink.onFailure`; whether that callback
ends observation is Sink policy, not an intrinsic terminal rule of `merge`.

## Examples

```ts
import { Effect, Ref } from "effect"
import { Fx, Sink } from "@typed/fx"

const program = Effect.gen(function* () {
  const deliveries = yield* Ref.make<Array<string>>([])
  const sink = Sink.make(
    () => Ref.update(deliveries, (xs) => [...xs, "failure"]),
    (value: string) => Ref.update(deliveries, (xs) => [...xs, value])
  )
  yield* Fx.merge(Fx.fail("left failed"), Fx.succeed("right continued")).run(sink)
  return yield* Ref.get(deliveries) // both "failure" and "right continued"
})
```
