()
| 396 | } |
| 397 | |
| 398 | func ExampleCatch() { |
| 399 | // Convert a slice of strings into a stream |
| 400 | strs := rill.FromSlice([]string{"1", "2", "3", "4", "5", "not a number 6", "7", "8", "9", "10"}, nil) |
| 401 | |
| 402 | // Convert strings to ints |
| 403 | // Concurrency = 3 |
| 404 | ids := rill.Map(strs, 3, func(s string) (int, error) { |
| 405 | randomSleep(500 * time.Millisecond) // simulate some additional work |
| 406 | return strconv.Atoi(s) |
| 407 | }) |
| 408 | |
| 409 | // Catch and ignore number parsing errors |
| 410 | // Concurrency = 2 |
| 411 | ids = rill.Catch(ids, 2, func(err error) error { |
| 412 | if errors.Is(err, strconv.ErrSyntax) { |
| 413 | return nil // Ignore this error |
| 414 | } |
| 415 | return err |
| 416 | }) |
| 417 | |
| 418 | // No error will be printed |
| 419 | printStream(ids) |
| 420 | } |
| 421 | |
| 422 | // The same example as for the [Catch], but using ordered versions of functions. |
| 423 | func ExampleOrderedCatch() { |
nothing calls this directly
no test coverage detected