Skip to content

How to get the difference between two slices #63

@natenho

Description

@natenho

Let's suppose I need to get all elements from A that don't appear in B slice (difference), but comparing only the name.

package main

import (
	"fmt"

	"github.com/wesovilabs/koazee"
)

type product struct {
	code int
	name string
}

var fruits1 = []*product{
	{code: 9, name: "apple"},
	{code: 4, name: "orange"},
	{code: 12, name: "lemon"},
}

var fruits2 = []*product{
	{code: 1000, name: "apple"}, // The code 1000 is intentional!! I need to compare only by name
}

func main() {
	stream := koazee.StreamOf(fruits1)	
	// ??
	
	stream.ForEach(func(p *product) {
		fmt.Printf("%d: \"%s\"\n", p.code, p.name)
	}).Do()
}

Should print

4: "orange"
12: "lemon

I'm trying to figure out a good way to do that using koazee.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions