Skip to content

wrigleyster/opt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Opt

a light weight 'optional' library for golang

Usage

func findElement(list []Element, name string) opt.Maybe[Element] {
    for _, element := range list {
        if element.name == name {
            return opt.Some(element)
        }
    }
    return opt.No[Element]()
}
func findYoungest(list []Element) opt.Maybe[Element] {
    return opt.First(sort.Sort(list))
}

john := findElement(userList, "john")
if john.Exists {
    register(john.Value)
}
cathy := findElement(userList, "cathy").orElse(Element{name: "cathy", age: 26})
register(cathy)

tinyTim := findYoungest(userList).orPanic()
register(tinyTim)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages