Documentation
¶
Overview ¶
This package contains functions intended for use with iter.Filter.
Index ¶
- func And[T any](filters ...func(T) bool) func(T) bool
- func GreaterThan[T constraints.Ordered](t T) func(T) bool
- func IsEven[T constraints.Integer](integer T) bool
- func IsOdd[T constraints.Integer](integer T) bool
- func IsZero[T comparable](t T) bool
- func LessThan[T constraints.Ordered](t T) func(T) bool
- func Or[T any](filters ...func(T) bool) func(T) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶
And returns a function that returns true when all provided functions return true.
When no functions 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 returns a function that returns true when a value is greater than a 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 IsEven ¶ added in v0.14.0
func IsEven[T constraints.Integer](integer T) bool
IsEven returns true when the provided integer is even
func IsOdd ¶ added in v0.14.0
func IsOdd[T constraints.Integer](integer T) bool
IsOdd returns true when the provided integer is odd
func IsZero ¶
func IsZero[T comparable](t T) bool
IsZero 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 returns a function that returns true when a value is less than a 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]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.