// Package strain implements collection operations
package strain
// Ints is a slice of ints
type Ints []int
// Lists is a two dimension slice of ints
type Lists [][]int
// Strings is a slice of strings
type Strings []string
// Keep creates a copy of base which elements satisfy the fn function
func (base Ints) Keep(fn func(int) bool) (out Ints) {
for _, element := range base {
if fn(element) {
out = append(out, element)
}
}
return out
}
// Discard creates a copy of base which elements does not satisfy the fn function
func (base Ints) Discard(fn func(int) bool) (out Ints) {
for _, element := range base {
if !fn(element) {
out = append(out, element)
}
}
return out
}
// Keep creates a copy of base which elements satisfy the fn function
func (base Lists) Keep(fn func([]int) bool) (out Lists) {
for _, element := range base {
if fn(element) {
out = append(out, element)
}
}
return out
}
// Keep creates a copy of base which elements satisfy the fn function
func (base Strings) Keep(fn func(string) bool) (out Strings) {
for _, element := range base {
if fn(element) {
out = append(out, element)
}
}
return out
}