Skip to content

Go: Result and Option type handling #1462

@asteurer

Description

@asteurer

I'm wondering if the Option and Result handling in the Go portion would be easier to use with some changes to the API. Here's one possibility:

import (
    wit "wit_component/wit_types"
)

optionExample := wit.Some("foo")
resultExample := wit.Ok[int, error](0)

// Current implementation
if optionExample.Tag() == wit.OptionSome {
// ...
}

if resultExample.Tag() == wit.ResultErr {
// ...
}

// Suggested implementation
if optionExample.IsNone() {
// ...
}

if resultExample.IsOk() {
// ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-goRelated to the Go code generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions