Transforms a slice to a map using a pivot callback to compute keys. Stops iteration immediately when an error is encountered.
// Error case - stops on first errorresult,err:=lo.KeyByErr([]string{"a","aa","aaa",""},func(strstring)(int,error){ifstr==""{return0,fmt.Errorf("empty string not allowed")}returnlen(str),nil})// map[int]string(nil), error("empty string not allowed")