Skip to content

result — examples

← all topics · 55 examples · page 2 of 2 · raw source ↓

Runs `go` → 40

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I03_Bind_Ok_Twice   topic: result   status: unverified
// verified behavior: Test.go(...) == 40

func step(n: int) -> Result<int, string> = ok(n * 2)
func go() -> int = parse(10).Bind((x) => step(x)).Bind((x) => step(x)).Unwrap()

Runs `go` → -1

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I04_Bind_Err_ShortCircuits   topic: result   status: unverified
// verified behavior: Test.go(...) == -1

func step(n: int) -> Result<int, string> = ok(n * 2)
func go() -> int = parse(-5).Bind((x) => step(x)).UnwrapOr(-1)

Runs `go` → 40

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I16_TryUnwrap_OkChain   topic: result   status: unverified
// verified behavior: Test.go(...) == 40

func step(n: int) -> Result<int, string> = ok(n * 2)
func go() -> int {
    let a = parse(10)?
    let b = step(a)?
    let c = step(b)?
    return c
}

Runs `go` → -1

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I17_TryUnwrap_ErrPropagates   topic: result   status: unverified
// verified behavior: Test.go(...) == -1

func chain(n: int) -> Result<int, string> {
    let a = parse(n)?
    return ok(a + 1)
}
func go() -> int = chain(-5).UnwrapOr(-1)

Runs `go` → 21

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_StdlibReadiness.cs::I20_Map_Bind_Match_Pipeline   topic: result   status: unverified
// verified behavior: Test.go(...) == 21

func dbl(n: int) -> Result<int, string> = ok(n * 2)
func go() -> int = parse(10).Map((x) => x + 1).Bind((x) => dbl(x)).Match((v) => v - 1, (e) => -1)