Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the difference between two slices #63

Open
natenho opened this issue Nov 21, 2021 · 0 comments
Open

How to get the difference between two slices #63

natenho opened this issue Nov 21, 2021 · 0 comments

Comments

@natenho
Copy link

natenho commented Nov 21, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant