Skip to content

Operation drop

Iván Corrales Solera edited this page Dec 9, 2018 · 2 revisions

stream.Drop

It remove all the ocurrences of the given element in the stream

Signature

func (s stream.Stream) Drop(element interface{}) (out stream)

Arguments

Name Type Description
element interface{} Element to be removed from the stream

Output

Name Type Description
out stream.Stream It returns the stream

Errors

Type Description
err.items-nil The stream is nil
err.invalid-argument A nil value can not be dropped from a Stream of non-pointers values
err.invalid-argument Element type must be the same than the elements in the stream

Example

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.Drop(&Food{"Sweets", false}).Do()
  for _, f := range stream.Out().Val().([]*Food) {
    fmt.Println(f.Name)
  }
}

Download

Benchmark

Remove an element (that exists) from a stream of strings

Test Identifier Stream Len Speed
BenchmarkAddString10-4 10 976 ns/op
BenchmarkAddString100-4 100 1571 ns/op
BenchmarkAddString1000-4 1000 11506 ns/op
BenchmarkAddString5000-4 5000 42881 ns/op

Remove an element (that does not exist) from a stream of strings

Test Identifier Stream Len Speed
BenchmarkDropString10UnExistingElement-4 10 706 ns/op
BenchmarkDropString100UnExistingElement-4 100 1580 ns/op
BenchmarkDropString1000UnExistingElement-4 1000 9650 ns/op
BenchmarkDropString5000UnExistingElement-4 5000 36940 ns/op