Skip to content

Instantly share code, notes, and snippets.

@juev
Created March 20, 2025 09:29
Show Gist options
  • Save juev/baf03d660fa083d4c6dd2280b6fcdc5f to your computer and use it in GitHub Desktop.
Save juev/baf03d660fa083d4c6dd2280b6fcdc5f to your computer and use it in GitHub Desktop.

Ergonomics

Источник

Use of a package like this may be pervasive if you really commit to it. This package was inspired by Rust's options implemenation. It might be worth considering dropping the repetative option. preceding the variants. Since importing names into the global namespace is to be avoided, the following import pattern may work for you:

import (
    "fmt"
 
    "github.com/BooleanCat/option"
)
 
var (
    Some = option.Some
    None = option.None
)
 
func main() {
    two := Some(2)
    fmt.Println(two)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment