Go with slightly better error handling primitives. Checkout the demo directory.
try sugar
content, err := ioutil.ReadFile(filename)
try err or stringtry desugared
...
if err != nil {
return make([]string, 1)[0], err
}The try statement expects two values.
- the error variable
- the type of the return value (this is needed because go has this convention of returning the zero value of a type incase of an error)
unwrap sugar
fileContent, err := readFile("sample.txt")
unwrap errunwrap desugared
...
if err != nil {
panic(err)
}The unwrap statement expects one value, the error variable.
just like try but this doesn't need a type
content, err := ioutil.ReadFile(filename)
bababooey errbababooey desugared
...
if err != nil {
return nil, err
}The bababooey statement expects one value, the error variable.
sugar for append
numbers := []int{1, 2, 3}
numbers = append(numbers, 4)append desugared
numbers := []uint{1, 2, 3}
@numbers <<< 4nix develop
cd src
./make.bash