Skip to content

Modern Result ValueOr

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Result › Result › ValueOr

ValueOr

Returns the value, or the fallback you pass if the Result failed.

Syntax

ValueOr( byref dflt as T ) byref as T

Examples

#import "std/outcome"
using outcome

dim good as Result( of int32, ustring ) = Ok( of int32, ustring )( 42 )
dim bad  as Result( of int32, ustring ) = Fail( of int32, ustring )( "nope" )

dim as int32 fallback = -1

print good.ValueOr( fallback )     '' 42
print bad.ValueOr( fallback )      '' -1

'' The branch-free alternative to Value( ): never raises, whichever side
'' the Result is on

Library: Result
Category: Result
Documented under: Members

Clone this wiki locally