variable / @typed/fx/Sink

flip

Exchanges a sink’s typed success and failure channels.

Package version
2.0.0-beta.7
Category
Failure handling
Since
1.0.0

Import

import { flip } from "@typed/fx/Sink";

Signatures

export declare const flip: <A, E, R>(sink: Sink<A, E, R>) => Sink<E, A, R>;

Why

Error-oriented consumers can be reused as value consumers, and vice versa, without changing the producer-side protocol.

Ownership and lifetime

A successful input becomes Cause.fail downstream. For an incoming Cause, the first typed Fail reason becomes a success and every remaining reason is discarded, including later failures, defects, or interruption reasons. A Cause with no typed failure passes through intact. The adapter is synchronous, ordered, and resource-free; use exit when the whole Cause must remain observable.

Examples

import { Effect } from "effect"
import * as Sink from "@typed/fx/Sink"
const errorsAsValues = Sink.flip(Sink.make(Effect.logError, (value: number) => Effect.log(value)))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source