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 cmp.Ordered](threshold T) func(T) bool
- func IsEqual[T comparable](value T) func(T) bool
- func IsEven[...](integer T) bool
- func IsOdd[...](integer T) bool
- func IsZero[T comparable](value T) bool
- func LessThan[T cmp.Ordered](threshold T) func(T) bool
- func Not[T any](fn func(T) bool) func(T) bool
- func NotEqual[T comparable](value T) func(T) bool
- func Or[T any](filters ...func(T) bool) func(T) bool
- func Passthrough[V any](value V) bool
- func Passthrough2[V any, W any](value1 V, value2 W) 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.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.And(filter.IsOdd, filter.GreaterThan(2))).Collect())
}
Output: [3]
func GreaterThan ¶
GreaterThan returns a function that returns true when the provided value is greater than a threshold.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.GreaterThan(2)).Collect())
}
Output: [3 4]
func IsEqual ¶
func IsEqual[T comparable](value T) func(T) bool
IsEqual returns a function that returns true when the provided value is equal to some value.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.IsEqual(2)).Collect())
}
Output: [2]
func IsEven ¶
func IsEven[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64](integer T) bool
IsEven returns true when the provided integer is even.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.IsEven).Collect())
}
Output: [2 4]
func IsOdd ¶
func IsOdd[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~int | ~int8 | ~int16 | ~int32 | ~int64](integer T) bool
IsOdd returns true when the provided integer is odd.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.IsOdd).Collect())
}
Output: [1 3]
func IsZero ¶
func IsZero[T comparable](value T) bool
IsZero returns true when the provided value is the zero value for its type.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{0, 1, 2, 3})).Filter(filter.IsZero).Collect())
}
Output: [0]
func LessThan ¶
LessThan returns a function that returns true when the provided value is less than a threshold.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.LessThan(3)).Collect())
}
Output: [1 2]
func Not ¶
Not returns a function that inverts the result of the provided function.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.Not[int](filter.IsEven)).Collect())
}
Output: [1 3]
func NotEqual ¶
func NotEqual[T comparable](value T) func(T) bool
NotEqual returns a function that returns true when the provided value is not equal to some value.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.NotEqual(2)).Collect())
}
Output: [1 3 4]
func Or ¶
Or returns a function that returns true when any of the provided functions return true.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.Or(filter.IsEven, filter.LessThan(3))).Collect())
}
Output: [1 2 4]
func Passthrough ¶
Passthrough returns a function that returns true for any value.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/slices"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
fmt.Println(iter.Iterator[int](slices.Values([]int{1, 2, 3, 4})).Filter(filter.Passthrough).Collect())
}
Output: [1 2 3 4]
func Passthrough2 ¶
Passthrough2 returns a function that returns true for any pair of values.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/future/maps"
"github.com/BooleanCat/go-functional/v2/iter"
"github.com/BooleanCat/go-functional/v2/iter/filter"
)
func main() {
numbers := maps.Collect(iter.Filter2(maps.All(map[int]string{1: "two"}), filter.Passthrough2))
fmt.Println(numbers[1])
}
Output: two
Types ¶
This section is empty.