Skip to content

mimoo/Bool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Proof of concept for options in Golang

This only works with booleans :D

import this in your project:

import "github.com/mimoo/Bool"

then you can use the Bool.Option type. It contains either a bool or an error:

func thing(arg bool) Bool.Option {
	if arg {
		return Bool.Ok(true)
	}
	return Bool.Err(fmt.Errorf("nope"))
}

and you are forced to handle it before you can use the value:

switch val := Bool.Match(thing(true)).(type) {
case bool:
    fmt.Println("a bool!", val)
case error:
    fmt.Println("an err!", val)
}

About

Bool as options in Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages