Skip to content

Operation last

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

stream.Last

It returns the element in the last position.

Signature

func (s stream.Stream) Last() (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.Last()
  fmt.Println(out.String())
}

Download

Benchmark

Asking for element in the last position

Test Identifier Stream Len Speed
BenchmarkLastString10-4 10 200 ns/op
BenchmarkLastString100-4 100 204 ns/op
BenchmarkLastString1000-4 1000 214 ns/op
BenchmarkLastString5000-4 5000 190 ns/op