stream.Add

Add a new element into the stream..

Function signature

    func Add(item interface{}) (stream S)

Arguments

Name Type Description
item Same type of elements in the stream New item to be added into the stream

Output

Name Type Description
stream koazee.S It returns the stream modified by the current operation

Errors

Type Message
err.items-nil An element can not be added in a nil stream
err.invalid-argument A nil value can not be added in a stream of non-pointers values
err.invalid-argument An element whose type is %s can not be added in a stream of type %s

Examples

package main

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

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

func main() {
	newList := koazee.Stream().
		Add(10).
		With(numbers).
		Out().
		Val().([]int)

	for _, number := range newList {
		fmt.Printf("%d\n", number)
	}
}
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() {
	newList := koazee.StreamOf(primates).
		Add(newPrimate("Pepe", 16, "Gibbon", male)).
		Out().
		Val().([]*primate)

	for _, primate := range newList {
		fmt.Printf("%s was invited to the party\n", primate.name)
	}
}