Skip to content

Operation at

Iván Corrales Solera edited this page Dec 2, 2018 · 13 revisions

stream.At

It returns the element in the given position.

Signature

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
}

Errors

Type Description
err.invalid-index The provided index is not valid, it must be between 0 and len(stream)-1

Example

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())
}

Benchmark

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