Skip to content

Operation removeDuplicates

Iván Corrales Solera edited this page Dec 2, 2018 · 1 revision

stream.RemoveDuplicates

It removes duplicated elements

Signature

func (s stream.Stream) RemoveDuplicated() (out *Output)

Arguments

N/A

Output

Name Type Description
out *stream.Output It's a pointer to the below structure
type Output struct {
  value reflect.Value
  error *errors.Error
}

Errors

Type Description
err.items-nil The stream doesn't have elements

Example

package main

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

var stream = koazee.StreamOf([]string{"Criminal", "Hunter", "BullFighter", "Murderer", "Hunter"})

func main() {
	stream = stream.RemoveDuplicates().Do()
	for _, c := range stream.Out().Val().([]string) {
		fmt.Printf("STOP %s\n", c)
	}
}

Download

Benchmark

Removing duplicated elements in a stream of strings

Test Identifier Stream Len Speed
BenchmarkDuplicatedString10-4 10 4695 ns/op
BenchmarkDuplicatedString10-4 100 39628 ns/op
BenchmarkDuplicatedString10-4 1000 413261 ns/op
BenchmarkDuplicatedString10-4 5000 2436386 ns/op