Documentation
¶
Overview ¶
Package filters for filtering, both in place and copy
Index ¶
- func Copy[S ~[]T, T any](a S, keepfn func(a T) bool) (out S)
- func FilterCopy[S ~[]T, T any](a S, keepfn func(a T) bool) Sdeprecated
- func FilterInPlace[S ~[]T, T any](a S, keepfn func(a T) bool) Sdeprecated
- func InPlace[S ~[]T, T any](a S, keepfn func(a T) bool) S
- func InvertBoolFunc[T any](fn func(a T) bool) func(a T) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶ added in v0.4.6
Copy returns a new slice with only the items that pass the filter The original slice is not modified.
For less memory usage, use FilterInPlace
func FilterCopy
deprecated
FilterCopy ...
Deprecated: As of mostly v0.4.5, this function simply calls Copy and will be removed in future versions.
Example ¶
package main
import (
"fmt"
"github.com/aerth/mostly/filters"
)
func main() {
nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
evenCopy := filters.Copy(nums, func(n int) bool {
return n%2 == 0
})
fmt.Println("Original:", nums)
fmt.Println("Copy:", evenCopy)
oddInPlace := filters.InPlace(nums, func(n int) bool {
return n%2 != 0
})
fmt.Println("InPlace:", oddInPlace)
fmt.Println("Backing:", nums)
}
Output: Original: [1 2 3 4 5 6 7 8 9 10] Copy: [2 4 6 8 10] InPlace: [1 3 5 7 9] Backing: [1 3 5 7 9 6 7 8 9 10]
func FilterInPlace
deprecated
func InPlace ¶ added in v0.4.6
InPlace modifies the slice in place. See Warning.
Warning: All slices that share the same backing array will be modified and need to be replaced by the return value.
func InvertBoolFunc ¶ added in v0.4.6
InvertBoolFunc to invert functions to true=keep that were designed for true=delete slices.DeleteFunc
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.