Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithErrorHandler ¶
func WithErrorHandler[T, U any](p rivo.Pipeable[T, U], errHandler rivo.Sync[struct{}]) rivo.Pipeable[T, U]
WithErrorHandler returns a pipeable that connects the input pipeable to an error handling pipeable. The items that don't contain errors are passed to the output stream, while the items that contain errors are passed to the error handling pipeable.
Example ¶
package main
import (
"context"
"fmt"
"strconv"
"github.com/agiac/rivo"
"github.com/agiac/rivo/errors"
)
func main() {
ctx := context.Background()
g := rivo.Of("1", "2", "3_", "4", "5**")
toInt := rivo.Map(func(ctx context.Context, i rivo.Item[string]) (int, error) {
return strconv.Atoi(i.Val)
})
logValue := rivo.Do[int](func(ctx context.Context, i rivo.Item[int]) {
fmt.Printf("Value: %d\n", i.Val)
})
errs := make([]error, 0)
errorHandler := rivo.Do[struct{}](func(ctx context.Context, i rivo.Item[struct{}]) {
errs = append(errs, i.Err)
})
<-rivo.Pipe3(g, errors.WithErrorHandler(toInt, errorHandler), logValue)(ctx, nil)
for _, err := range errs {
fmt.Printf("Error: %v\n", err)
}
}
Output: Value: 1 Value: 2 Value: 4 Error: strconv.Atoi: parsing "3_": invalid syntax Error: strconv.Atoi: parsing "5**": invalid syntax
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.