-
Notifications
You must be signed in to change notification settings - Fork 30
Operation add
Iván Corrales Solera edited this page Dec 2, 2018
·
8 revisions
It adds a new element in the stream (the element will be added in the last position)
func (s stream.Stream) Add(element interface{}) (out stream)Arguments
| Name | Type | Description |
|---|---|---|
| element | interface{} | New value to be added into the stream |
Output
| Name | Type | Description |
|---|---|---|
| out | stream.Stream | It returns the stream |
| Type | Description |
|---|---|
| err.items-nil | The stream is nil |
| err.invalid-argument | A nil value can not be added in a stream of non-pointers values |
| err.invalid-argument | Element type must be the same than the elements in the stream |
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
type Food struct {
Name string
Healthy bool
}
var foodSlice = []*Food{
{"Vegetables", true},
{"Nuts", true},
{"Sweets", false},
}
var stream = koazee.StreamOf(foodSlice)
func main() {
stream = stream.Add(&Food{"Fruit", true}).Do()
for _, f := range stream.Out().Val().([]*Food) {
fmt.Println(f.Name)
}
}Adding a new element in a stream of strings
| Test Identifier | Stream Len | Speed |
|---|---|---|
| BenchmarkAddString10-4 | 10 | 718 ns/op |
| BenchmarkAddString100-4 | 100 | 1276 ns/op |
| BenchmarkAddString1000-4 | 1000 | 7561 ns/op |
| BenchmarkAddString5000-4 | 5000 | 44036 ns/op |
@2018 Koazee by Iván Corrales Solera [email protected]