filters

package
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package filters for filtering, both in place and copy

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy added in v0.4.6

func Copy[S ~[]T, T any](a S, keepfn func(a T) bool) (out S)

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

func FilterCopy[S ~[]T, T any](a S, keepfn func(a T) bool) S

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 FilterInPlace[S ~[]T, T any](a S, keepfn func(a T) bool) S

FilterInPlace ...

Deprecated: As of mostly v0.4.5, this function simply calls InPlace and will be removed in future versions.

func InPlace added in v0.4.6

func InPlace[S ~[]T, T any](a S, keepfn func(a T) bool) S

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

func InvertBoolFunc[T any](fn func(a T) bool) func(a T) bool

InvertBoolFunc to invert functions to true=keep that were designed for true=delete slices.DeleteFunc

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL