Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
destel committed Jul 21, 2024
1 parent f7f8845 commit 6cf9731
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,41 @@ func ExampleOrderedFilter() {
printStream(evens)
}

func ExampleFilterMap() {
numbers := rill.FromSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, nil)

// Keep only odd numbers and square them
// Concurrency = 3; Unordered
squares := rill.FilterMap(numbers, 3, func(x int) (int, bool, error) {
if x%2 == 0 {
return 0, false, nil
}

randomSleep(1000 * time.Millisecond) // simulate some additional work
return x * x, true, nil
})

printStream(squares)
}

// The same example as for the [FilterMap], but using ordered versions of functions.
func ExampleOrderedFilterMap() {
numbers := rill.FromSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, nil)

// Keep only odd numbers and square them
// Concurrency = 3; Ordered
squares := rill.OrderedFilterMap(numbers, 3, func(x int) (int, bool, error) {
if x%2 == 0 {
return 0, false, nil
}

randomSleep(1000 * time.Millisecond) // simulate some additional work
return x * x, true, nil
})

printStream(squares)
}

func ExampleFirst() {
numbers := rill.FromSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, nil)

Expand Down

0 comments on commit 6cf9731

Please sign in to comment.