filters

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And[T any](filters ...func(T) bool) func(T) bool

And aggregates multiple filters for use with iter.Filter (and iter.Exclude) to create a filter that returns true when all provided filters return true.

If no filters are provided the result is always true.

Example
package main

import (
	"fmt"

	"github.com/BooleanCat/go-functional/iter"
	"github.com/BooleanCat/go-functional/iter/filters"
)

func main() {
	items := iter.Filter[int](iter.Lift([]int{1, 2, 3, 4, 5, 6, 7}), filters.And(
		filters.GreaterThan(2),
		filters.LessThan(7),
	))
	fmt.Println(items.Collect())
}
Output:

[3 4 5 6]

func GreaterThan

func GreaterThan[T constraints.Ordered](t T) func(T) bool

GreaterThan creates a filter for use with iter.Filter that returns true when a value is greater than the provided threshold.

Example
package main

import (
	"fmt"

	"github.com/BooleanCat/go-functional/iter"
	"github.com/BooleanCat/go-functional/iter/filters"
)

func main() {
	items := iter.Filter[int](iter.Lift([]int{1, 2, 3, 4, 5, 1}), filters.GreaterThan(2))
	fmt.Println(items.Collect())
}
Output:

[3 4 5]

func IsZero

func IsZero[T comparable](t T) bool

IsZero is a filter intended for use with iter.Filter that returns true when the provided value is equal to its zero value.

Example
package main

import (
	"fmt"

	"github.com/BooleanCat/go-functional/iter"
	"github.com/BooleanCat/go-functional/iter/filters"
)

func main() {
	items := iter.Exclude[int](iter.Lift([]int{1, 2, 3, 0, 4}), filters.IsZero[int])
	fmt.Println(items.Collect())
}
Output:

[1 2 3 4]

func LessThan

func LessThan[T constraints.Ordered](t T) func(T) bool

LessThan creates a filter for use with iter.Filter that returns true when a value is less than the provided threshold.

Example
package main

import (
	"fmt"

	"github.com/BooleanCat/go-functional/iter"
	"github.com/BooleanCat/go-functional/iter/filters"
)

func main() {
	items := iter.Filter[int](iter.Lift([]int{1, 2, 3, 4, 5, 1}), filters.LessThan(2))
	fmt.Println(items.Collect())
}
Output:

[1 1]

func Or added in v0.12.0

func Or[T any](filters ...func(T) bool) func(T) bool

And aggregates multiple filters for use with iter.Filter (and iter.Exclude) to create a filter that returns true when one of the provided filters return true.

If no filters are provided the result is always true.

Types

This section is empty.

Jump to

Keyboard shortcuts

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