-
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 |
err.items-nil | The stream doesn't have elements |
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
var stream = koazee.StreamOf([]string{"Dog","Cat","Monkey","Rabbit","Turtle"})
func main() {
out:=stream.At(1)
fmt.Println(out.String())
}
Asking for element in a random position
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]