Skip to content

proposal: Go 2: builtin: must function #32219

Closed
@pjebs

Description

@pjebs

It would be great if there was a generic must function in "builtin" package.

It would be equivalent to this:


eg. 
Say we have an arbitrary function that looks like this:
x, y, z, err := function()

x, y, z is of arbitrary type T1, T2, T3 respectively.

the proposed must( function() ) function will return x of type T1 if err == nil and panic(err) if err != nil

The function is better suited for functions which return 2 values, the last of which is type error. But it can be generalized to any number of return values provided the final return value is of type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeLanguageChangeSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.v2An incompatible library change

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions