Katxupa
  • 👋Welcome to Katxupa Extension Library
  • Why Katxupa?
    • 🍻What makes Katxupa special?
    • ✨Key Features
  • Get a taste of Katxupa
    • 🍲Installation
    • 🍜Usage
      • 🍻Scope Functions
        • Function Selection
        • Distinctions
        • Functions
          • letIt
          • withIt
          • runIt
          • applyIt
          • alsoIt
          • takeIf and takeUnless
      • 😎Null Safety
        • TypeScript Null-Safety
        • Optional Chaining for JavaScript
      • ⏰Duration
      • ➖Reducer
      • 📏Range
      • 🏃‍♂️Result
      • 🤼Either
      • 🟰Compare
      • ⚔️Global Utility Functions
    • 🤌Dip Dive
      • Optional
      • Range
      • Duration
      • Reducer
      • Collections
        • Array
        • Set
  • 🙏Support
    • Source Code
    • ESLint Config
    • TypeScript Docs
    • Manuel Santos Linkedin
Powered by GitBook
On this page
  1. Get a taste of Katxupa
  2. Usage

Result

Represents the result of an operation that can either succeed with a value or fail with an error.

const orResult: Result<number, string> = ok(42);
const errorResult: Result<number, string> = error("An error occurred");

orResult.get(); // Returns 42
errorResult.get(); // Throws Error("An error occurred")

orResult.extract(); // Returns {value: 42}
errorResult.extract(); // Returns {error: "An error occurred"}

orResult.toOptional(); // Optional with value 42
errorResult.toOptional(); // Optional with no value
PreviousRangeNextEither

Last updated 1 year ago

🍜
🏃‍♂️