-
Notifications
You must be signed in to change notification settings - Fork 31
Operation take
Iván Corrales Solera edited this page Dec 13, 2018
·
1 revision
It returns a stream with elements between the given indexes (both included)
func (s stream.Stream) Take(firstIndex,lastIndex int ) (out stream.Stream)
Arguments
Name | Type | Description |
---|---|---|
firstIndex | int | First index to be taken |
lastIndex | int | Last index to be taken |
Output
Name | Type | Description |
---|---|---|
out | stream.Stream | It returns the stream |
Type | Description |
---|---|
err.items-nil | The stream is nil |
err.invalid-index | The indexes are not valid |
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
type Person struct {
FirstName string
}
var people = []*Person{
{"Cat"},
{"Dog"},
{"Rat"},
{"Canary"},
{"Gibbon"},
}
var stream = koazee.StreamOf(people)
func main() {
stream = stream.Take(1, 3).Do()
for _, f := range stream.Out().Val().([]*Person) {
fmt.Println(f.FirstName)
}
}
Taking the elements between positions 1 and len-1
Test Identifier | Stream Len | Speed |
---|---|---|
BenchmarkTakeNumbers1000Between1and9-4 | 10 | 326 ns/op |
BenchmarkTakeNumbers1000Between1and99-4 | 100 | 323 ns/op |
BenchmarkTakeNumbers1000Between1and999-4 | 1000 | 335 ns/op |
BenchmarkTakeNumbers2500etween1and2499-4 | 5000 | 321 ns/op |
@2018 Koazee by Iván Corrales Solera [email protected]