filter

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

This package contains functions intended for use with iter.Filter.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GreaterThan

func GreaterThan[V cmp.Ordered](value V) func(V) 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/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

func GreaterThanEqual[T cmp.Ordered](t T) func(T) bool

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

func LessThan[T cmp.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/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

func LessThanEqual[T cmp.Ordered](t T) func(T) bool

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.

Jump to

Keyboard shortcuts

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