Skip to content

goserg/optional

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optional

Golang library providing generic optional type. Provides zero allocation alternative for using pointer to optional structs.

Example

Use of default value

func generateURL(host string, port optional.Optional[int]) string {
	return fmt.Sprintf("postgres://%s:%d", host, port.GetOrElse(5432))
}

func main() {
	fmt.Println(generateURL("postgres", optional.New(5533)))
	// Prints
	// postgres://postgres:5533
	fmt.Printf(generateURL("postgres", optional.None[int]()))
	// Prints
	// postgres://postgres:5432
}

Releases

No releases published

Packages

No packages published

Languages