Skip to content

Operation pop

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

stream.Pop

It returns the element in the first position and the stream withouth the first element

In case of there'were operatios peding to be executed, these will be performed before taking the element.

Signature

func (s stream.Stream) Pop() (out *Output,sOut stream.Stream)

Arguments

N/A

Output

Name Type Description
out *stream.Output It's a pointer to the below structure
sOut stream.Stream It contains the new stream
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, sOut := stream.Pop()
  fmt.Println(out.String())
  fmt.Printf("Len %d\n", len(sOut.Out().Val().([]string)))
}

Download

Benchmark

Asking for element in the first position

Test Identifier Stream Len Speed
BenchmarkPopString10-4 10 344 ns/op
BenchmarkPopString100-4 100 345 ns/op
BenchmarkPopString1000-4 1000 343 ns/op
BenchmarkPopString5000-4 5000 344 ns/op