markphelps / optional

Optional is a library of optional Go types
https://godoc.org/github.com/markphelps/optional
MIT License
209 stars 19 forks source link

How do I actually create bottom values? #26

Open cgohla opened 1 year ago

cgohla commented 1 year ago

It's not clear to me at all from the README or from the generated code, how to create the bottom value (or Nothing in Haskell parlance).

I have this generated code:

// OptionalFlavor is an optional Flavor.
type OptionalFlavor struct {
        value *Flavor
}

// NewOptionalFlavor creates an optional.OptionalFlavor from a Flavor.
func NewOptionalFlavor(v Flavor) OptionalFlavor {
        return OptionalFlavor{&v}
}

so if I have a Flavor I know how to get an OptionalFlavor. What I expected to find here was a nullary function that returns the Nothing case.

Perhaps I don't understand how this is supposed to work, or the README needs clarification.

cgohla commented 1 year ago

Tangentially, being a sum type, I expected there to be a tag field in the generated struct. So I would like to know how the Nothing case is actually represented (Sorry, I'm new to golang).