Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrDifferentLength = errors.New("arrays must be the same length")
)
Functions ¶
func Apply ¶
Apply applies a function to each element of an array
It returns an array of errors, where each error corresponds to the result of the function applied to the element at the same index ¶
It returns nil if all function calls return nil
Example ¶
arr := []int{1, 2, 3, 4, 5}
err := Apply(func(a int) error {
if a%2 == 0 {
return nil
}
return errors.New("testErr")
}, arr)
if err != nil {
fmt.Println(err)
}
Output: 3 errors
func Map ¶
Map applies a function to each element of an array
It returns an array of results and an array of errors, where each result and error corresponds to the result of the function applied to the element at the same index
It returns nil if all function calls return nil
Example ¶
arr := []int{1, 2, 3, 4, 5}
doubled, err := Map(func(a int) (int, error) {
return a * 2, nil
}, arr)
if err != nil {
fmt.Println(err)
}
fmt.Println(doubled)
Output: [2 4 6 8 10]
Types ¶
type MapError ¶ added in v0.0.2
func NewMapError ¶ added in v0.0.2
Click to show internal directories.
Click to hide internal directories.