Skip to content

Operation first

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

stream.First

It returns the element in the first position.

Signature

func (s stream.Stream) First() (out *Output)

Arguments

N/A

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.items-nil The stream doesn't have elements

Example

package main

import (
  "fmt"
  "github.com/wesovilabs/koazee"
)

var stream = koazee.StreamOf([]string{"Dog","Cat","Monkey","Rabbit","Turtle"})

func main() {
  out:=stream.First()
  fmt.Println(out.String())
}

Download

Benchmark

Asking for element in the first position

Test Identifier Stream Len Speed
BenchmarkFirstString10-4 10 235 ns/op
BenchmarkFirstString100-4 100 191 ns/op
BenchmarkFirstString1000-4 1000 370 ns/op
BenchmarkFirstString5000-4 5000 259 ns/op