Skip to content

onemouth/go-errormonad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-errormonad

A state monad for error handling in golang

Example

in monad_test.go

func TestReadFileBase64JSON(t *testing.T) {
	m := Return("testdata/test.base64")
	m = Bind(m, ReadFile)
	m = Bind(m, BytesToStr)
	m = Bind(m, Base64DecodeString)
	m = Bind(m, JSONUnmarshal)
	jsonMap, err := m(nil)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(jsonMap)
}

In the above example, usually, you should write if err... four times.

Howerver, by taking advatage of the monad, you only need check once in the end.

About

a monad for error handling in golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages