-
Notifications
You must be signed in to change notification settings - Fork 31
Operation set
Iván Corrales Solera edited this page Dec 15, 2018
·
2 revisions
It replaces the element in the given index by the provided value
func (s stream.Stream) Set(index int, value interface{}) (out stream)
Arguments
Name | Type | Description |
---|---|---|
index | int | Index |
value | 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.Set(0, &Food{"Fruit", true}).Do()
for _, f := range stream.Out().Val().([]*Food) {
fmt.Println(f.Name)
}
}
Repleace element in position 0
Test Identifier | Stream Len | Speed |
---|---|---|
BenchmarkSetString10-4 | 10 | 771 ns/op |
BenchmarkSetString100-4 | 100 | 1451 ns/op |
BenchmarkSetString1000-4 | 1000 | 6717 ns/op |
BenchmarkSetString5000-4 | 5000 | 32890 ns/op |
@2018 Koazee by Iván Corrales Solera [email protected]