-
Notifications
You must be signed in to change notification settings - Fork 31
Operation foreach
Iván Corrales Solera edited this page Dec 2, 2018
·
1 revision
It does something over all the elements in the stream.
func (s stream.Stream) Filter(fn func(interface{}) ) (out stream.Stream)
Arguments
Name | Type | Description |
---|---|---|
fn | func | This function must receive an argument of type the same that the elements in the stream and it doesn’t return any value |
Output
N/A
Type | Description |
---|---|
err.items-nil | The stream is nil |
err.invalid-argument | The forEach operation requires a function as argument |
err.invalid-argument | The provided function must retrieve 1 argument |
err.invalid-argument | The provided function can not return any value |
err.invalid-argument | The type of the argument in the provided function must be the same than the elements in the stream |
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
var stream = koazee.StreamOf([]int{1, 2, 3, 4, 5})
func main() {
stream.ForEach(func(val int) {fmt.Printf("Double of %d is %d\n",val,2*val) }).Do()
}
Iterating over a stream of int and printing the value
Test Identifier | Stream Len | Speed |
---|---|---|
BenchmarkForEachNumbers10Print-4 | 10 | 445 ns/op |
BenchmarkForEachNumbers100Print-4 | 100 | 647 ns/op |
BenchmarkForEachNumbers1000Print-4 | 1000 | 2980 ns/op |
BenchmarkForEachNumbers5000Print-4 | 5000 | 7260 ns/op |
@2018 Koazee by Iván Corrales Solera [email protected]