Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithErrorHandler ¶
func WithErrorHandler[T, U any](p rivo.Pipeline[T, U], errHandler rivo.Pipeline[struct{}, rivo.None]) rivo.Pipeline[T, U]
WithErrorHandler returns a pipeline that connects the input pipeline to an error handling pipeline. 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 pipeline.
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.