📦
unwrapit
  • 👋Welcome to unwrapit
  • Intro
    • 💡Why use it?
    • ✨Getting Started
  • APIs
    • 🔨wrap
    • 🔨unwrap
    • 🔨unwrapOr
    • 🔨unwrapOrElse
    • 🔨expect
    • 🔨mapErr
    • 🔨defineWrapConfig
    • 🔨ok
    • 🔨err
  • Type
    • 🔧Result
    • 🔧WrapConfig
    • 🔧WrapOption
    • 🔧Panic
  • Recipe
    • 🎨Export Wrapped Functions
    • 🎨Return Result Without `wrap` it
Powered by GitBook
On this page
  1. Recipe

Return Result Without `wrap` it

PreviousExport Wrapped Functions

Last updated 1 year ago

In some cases, you might want to define your own logic to determine whether to return an ok value or err value. You can do this by using and API.

import {ok, err, type Result} from 'unwrapit'

export function addNumber(a: number, b: number): Result<number, string> {
    if (a < b) {
        return err('a should greater than b')
    }
    
    if (a === b) {
        return err("a shouldn't equal to b")
    }
    
    return ok(a + b)
}
🎨
ok
err