Skip to content

Operation count

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

stream.Count

It returns the number of elements in the stream.

Signature

func (s stream.Stream) Count()  (total int,err *errors.Error)

Arguments

N/A

Output

Name Type Description
total int Number of elements
err *errors.Error Error in case of something didn't work

Errors

Type Description
err.items-nil Count of a nil stream is not permitted

Example

package main

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

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

func main() {
  count,_:=stream.Count()
  fmt.Println(count)
}

Download

Benchmark

Counting the number of elements in a stream o strings

Test Identifier Stream Len Speed
BenchmarkCountString10-4 10 101 ns/op
BenchmarkCountString10-4 100 98.6 ns/op
BenchmarkCountString10-4 1000 108 ns/op
BenchmarkCountString10-4 5000 96.5 ns/op