🎨Return Result Without `wrap` it

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 ok and err 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)
}

Last updated