stream.Count

Return the number of elements in the stream.

Function signature

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

Arguments

None

Output

Name Type Description
total int Number of elements in the stream
err *errors.Error Returns nil when the operation was fine and error when something didn’t work

Errors

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

Examples

package main

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

var numbers = []int{1, 3, 5, 7, 9}

func main() {
	total, _ := koazee.Stream().
		With(numbers).
		Count()
	fmt.Printf("There's %d elements in the list", total)

}
package main

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

type genre int

const (
	female genre = iota
	male
)

type primate struct {
	name   string
	age    int
	family string
	genre  genre
}

func newPrimate(name string, age int, family string, genre genre) *primate {
	return &primate{
		name:   name,
		age:    age,
		family: family,
		genre:  genre,
	}
}

var primates = []*primate{
	newPrimate("John", 15, "Capuchin", male),
	newPrimate("Laura", 12, "Squirrel monkey", female),
	newPrimate("Benjamin", 23, "Spider monkey", male),
	newPrimate("George", 19, "Golden Lion Tamarin", male),
	newPrimate("Jane", 33, "Orangutan", female),
	newPrimate("Sarah", 7, "Gibbon", female),
}

func main() {
	total, _ := koazee.StreamOf(primates).
		Count()
	fmt.Printf("There's %d monkeies coming to the party", total)

}