-
Notifications
You must be signed in to change notification settings - Fork 31
Operation at
Iván Corrales Solera edited this page Dec 2, 2018
·
13 revisions
It returns the element in the given position.
func (s stream.Stream) At(index int) (out *Output)
Arguments
Name | Type | Description |
---|---|---|
index | int | Index in the stream, from 0-len(stream)-1 |
Output
Name | Type | Description |
---|---|---|
out | *stream.Output | It's a pointer to the below structure |
type Output struct {
value reflect.Value
error *errors.Error
}
Type | Description |
---|---|
err.invalid-index | The provided index is not valid, it must be between 0 and len(stream)-1 |
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
var numbers = []int{1, 3, 5, 7, 9}
func main() {
out := koazee.Stream().
With(numbers).
At(2)
fmt.Printf("%d\n", out.Val())
}
Adding a new element in a stream of strings
Test Identifier | Stream Len | Speed |
---|---|---|
BenchmarkAtString10-4 | 10 | 160 ns/op |
BenchmarkAtString100-4 | 100 | 229 ns/op |
BenchmarkAtString1000-4 | 1000 | 211 ns/op |
BenchmarkAtString5000-4 | 5000 | 156 ns/op |
@2018 Koazee by Iván Corrales Solera [email protected]