internal/platform/algorithm/algorithm.go (21 lines of code) (raw):
package algorithm
func Filter[T any](iterable []T, predicate func(T) bool) []T {
var result []T
for _, item := range iterable {
if predicate(item) {
result = append(result, item)
}
}
return result
}
func Unique[T comparable](iterable []T) []T {
seen := map[T]bool{}
predicate := func(item T) bool {
if seen[item] {
return false
}
seen[item] = true
return true
}
return Filter(iterable, predicate)
}