It's pretty often that one needs to exclude some entries from slice by some keys
There's lo.Without which could be useful
But it's not always convenient cause it could be so that you have an entity and only its' keys
In that case it could be useful to have
SliceToSet[K comparable](values []K) map[K]struct{}
For example:
type Entity struct {
Key string
Value string
}
func filter(entities []Entity) []Entity {
blackList := SliceToSet(getBlackList()) // map[string]struct{}
return lo.Filter(entities, func(e Entity, _ int) bool {
_, ok := blackList[e.Key]
return !ok
})
}
Yeah, one could simply return the map from getBlackList() or use lo.Contains
But to return that map SliceToSet could still be useful and lo.Contains is not always optimal
And I guess there's lots of other applications of such a function
Also seems like it could be useful adding
WithoutBy[T any, K comparable](collection []T, extract func(T) K, exclude ...K) []T
It's pretty often that one needs to exclude some entries from slice by some keys
There's
lo.Withoutwhich could be usefulBut it's not always convenient cause it could be so that you have an entity and only its' keys
In that case it could be useful to have
For example:
Yeah, one could simply return the map from
getBlackList()or uselo.ContainsBut to return that map
SliceToSetcould still be useful andlo.Containsis not always optimalAnd I guess there's lots of other applications of such a function
Also seems like it could be useful adding