Documentation ¶
Overview ¶
This package contains functions intended for use with iter.Filter.
Index ¶
- func GreaterThan[V cmp.Ordered](value V) func(V) bool
- func GreaterThanEqual[T cmp.Ordered](t T) func(T) bool
- func IsEven[...](integer V) bool
- func IsOdd[...](integer V) bool
- func IsZero[V comparable](value V) bool
- func LessThan[T cmp.Ordered](t T) func(T) bool
- func LessThanEqual[T cmp.Ordered](t T) func(T) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GreaterThan ¶
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/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Lift([]int{1, 2, 3, 4, 5}).Filter(filter.GreaterThan(2)) fmt.Println(numbers.Collect()) }
Output: [3 4 5]
func GreaterThanEqual ¶
GreaterThanEqual returns a function that returns true when a value is greater than or equal to a threshold.
Example ¶
package main import ( "fmt" "github.com/BooleanCat/go-functional/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Lift([]int{1, 2, 3, 4, 5}).Filter(filter.GreaterThanEqual(3)) fmt.Println(numbers.Collect()) }
Output: [3 4 5]
func IsEven ¶
func IsEven[V ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr](integer V) bool
IsEven returns true when the provided integer is even.
Example ¶
package main import ( "fmt" "github.com/BooleanCat/go-functional/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Exclude[int](iter.Lift([]int{1, 2, 3, 4, 5}), filter.IsEven) fmt.Println(numbers.Collect()) }
Output: [1 3 5]
func IsOdd ¶
func IsOdd[V ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr](integer V) bool
IsOdd returns true when the provided integer is odd.
Example ¶
package main import ( "fmt" "github.com/BooleanCat/go-functional/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Exclude[int](iter.Lift([]int{1, 2, 3, 4, 5}), filter.IsOdd) fmt.Println(numbers.Collect()) }
Output: [2 4]
func IsZero ¶
func IsZero[V comparable](value V) bool
IsZero returns true when the provided value is equal to its zero value.
Example ¶
package main import ( "fmt" "github.com/BooleanCat/go-functional/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Exclude[int](iter.Lift([]int{1, 2, 3, 0, 4}), filter.IsZero) fmt.Println(numbers.Collect()) }
Output: [1 2 3 4]
func LessThan ¶
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/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Lift([]int{1, 2, 3, 4, 5}).Filter(filter.LessThan(3)) fmt.Println(numbers.Collect()) }
Output: [1 2]
func LessThanEqual ¶
LessThanEqual returns a function that returns true when a value is less than or equal to a threshold.
Example ¶
package main import ( "fmt" "github.com/BooleanCat/go-functional/v2/iter" "github.com/BooleanCat/go-functional/v2/iter/filter" ) func main() { numbers := iter.Lift([]int{1, 2, 3, 4, 5}).Filter(filter.LessThanEqual(3)) fmt.Println(numbers.Collect()) }
Output: [1 2 3]
Types ¶
This section is empty.