Hyperlinkv0.8.0-beta.28

Result

Result.flipconsteffect/Result.ts:1521
<A, E>(self: Result<A, E>): Result<E, A>

Swaps the success and failure channels of a Result.

When to use

Use to swap channels when failure-focused operations are easier through success-oriented combinators.

Details

  • Success<A> becomes Failure<A> (i.e., Result<E, A>)
  • Failure<E> becomes Success<E> (i.e., Result<E, A>)
  • Useful when you want to apply success-oriented operations (like map) to the error channel, then flip back

Example (Swapping channels)

import { Result } from "effect"

console.log(Result.flip(Result.succeed(42)))
// Output: { _tag: "Failure", failure: 42, ... }

console.log(Result.flip(Result.fail("error")))
// Output: { _tag: "Success", success: "error", ... }
transformingmapError
Source effect/Result.ts:15212 lines
export const flip = <A, E>(self: Result<A, E>): Result<E, A> =>
  isFailure(self) ? succeed(self.failure) : fail(self.success)