Skip to content

Operation lastIndexOf

Iván Corrales Solera edited this page Dec 14, 2018 · 1 revision

stream.LastIndexOf

It returns the last index of the given element in the stream

Signature

func (s stream.Stream) LastIndexOf(element interface{}) (index int,err error)

Arguments

Name Type Description
element interface{} Element to be found in the stream

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 is nil
err.invalid-argument A nil value can not be dropped from a Stream of non-pointers values
err.invalid-argument Element type must be the same than the elements in the stream

Example

package main

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

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

func main() {
	index,_:=stream.LastIndexOf("Monkey")
	fmt.Println(index)
}

Download

Benchmark

LastIndexOf the first element in the stream

Test Identifier Stream Len Speed
BenchmarkLastIndexOfString10FirstElement-4 10 274 ns/op
BenchmarkLastIndexOfString100FirstElement-4 100 325 ns/op
BenchmarkLastIndexOfString1000FirstElement-4 1000 582 ns/op
BenchmarkLastIndexOfString5000FirstElement-4 5000 3832 ns/op

LastIndexOf the last element in the stream

Test Identifier Stream Len Speed
BenchmarkLastIndexOfString10LastElement-4 10 275 ns/op
BenchmarkLastIndexOfString100LastElement-4 100 279 ns/op
BenchmarkLastIndexOfString1000LastElement-4 1000 280 ns/op
BenchmarkLastIndexOfString5000LastElement-4 5000 279 ns/op

LastIndexOf a non found element

Test Identifier Stream Len Speed
BenchmarkLastIndexOfString10NotFound-4 10 243 ns/op
BenchmarkLastIndexOfString100NotFound-4 100 361 ns/op
BenchmarkLastIndexOfString1000NotFound-4 1000 1433 ns/op
BenchmarkLastIndexOfString5000NotFound-4 5000 7267 ns/op