elliotchance / pie

šŸ• Enjoy a slice! A utility library for dealing with slices and maps that focuses on type safety and performance.
https://pkg.go.dev/github.com/elliotchance/pie/v2
MIT License
1.96k stars 91 forks source link

I want to add a new Functions - Remove #171

Open Luoxin opened 3 years ago

Luoxin commented 3 years ago

I want to add removeļ¼Œlike:

listA := pie.Strings{"1", "2"}
listB := pie.Strings{"1", "3"}

// [ "2" ]
fmt.Println(listA.Remove(listB...))

In some scenarios, there will be a desire to weed out the data in slice A from the data in slice B

Luoxin commented 3 years ago

I have made some attempts

172

chocolacula commented 1 year ago

@elliotchance What is the actual status? I would be happy to add similar function with index based removing in Go idiomatic(but not perfect) way s = append(s[:idx], s[idx+1:]...) within. I guess behaviour described above is exactly the same as Intersect

elliotchance commented 1 year ago

Intersect creates a set of elements that exist in both sets. I believe what @Luoxin is talking about here is "except" which results in the elements that do not exist in another set.

Speaking more broadly, it would be nice to have a Set type in this library for dealing with unordered unique items where these kinds of operations make sense. Otherwise, union operations on non-unique elements can be ambiguous.

chocolacula commented 1 year ago

Of course, Except

chocolacula commented 1 year ago

Added in https://github.com/elliotchance/pie/pull/194