Extends samber/lo with error handling and other useful utilities.
go get github.com/otterize/lox
package main
import (
"fmt"
"github.com/otterize/lox"
"strings"
)
func main() {
names, err := lox.MapErr([]string{"Otter", "Other", "Utter"}, func(s string, i int) (string, error) {
if s == "" {
return "", fmt.Errorf("empty name")
}
return s, nil
})
if err != nil {
panic(err)
}
fmt.Printf("Names: %s", strings.Join(names, ","))
}