Skip to content

strings: add First function? #14423

@abbgrade

Description

@abbgrade

Hi,

i would like to have a string.coalesce function, that returns the first not empty string.
I think, it's an clean solution for realizing default values.

It exists in T-SQL for example.

// returns the first not empty string of certain strings
func coalesce(values ...string) string {
    for _, value := range values {
        if value != "" {
            return value
        }
    }
    return ""
}

What do you think?

Best regards,
Steffen

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions