SliceExt

package
v0.2.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterByNegativeWeight

func FilterByNegativeWeight[T any](S []T, weightFunc func(T) int) []T

FilterByNegativeWeight is a function that iterates over the slice and applies the weight function to each element. The returned slice contains the elements with the minimum weight. If multiple elements have the same minimum weight, they are all returned.

Parameters:

  • S: slice of elements.
  • weightFunc: function that takes an element and returns an integer.

Returns:

  • []T: slice of elements with the minimum weight.

func FilterByPositiveWeight

func FilterByPositiveWeight[T any](S []T, weightFunc func(T) int) []T

FilterByPositiveWeight is a function that iterates over the slice and applies the weight function to each element. The returned slice contains the elements with the maximum weight. If multiple elements have the same maximum weight, they are all returned.

Parameters:

  • S: slice of elements.
  • weightFunc: function that takes an element and returns an integer.

Returns:

  • []T: slice of elements with the maximum weight.

func SliceFilter

func SliceFilter[T any](S []T, filter PredicateFilter[T]) []T

SliceFilter is a function that iterates over the slice and applies the filter function to each element. The returned slice contains the elements that satisfy the filter function.

Parameters:

  • S: slice of elements.
  • filter: function that takes an element and returns a bool.

Returns:

  • []T: slice of elements that satisfy the filter function.

Types

type PredicateFilter

type PredicateFilter[T any] func(T) bool

PredicateFilter is a type that defines a slice filter function.

Parameters:

  • T: The type of the elements in the slice.

Returns:

  • bool: True if the element satisfies the filter function, otherwise false.

func Intersect

func Intersect[T any](funcs ...PredicateFilter[T]) PredicateFilter[T]

Intersect returns a PredicateFilter function that checks if an element satisfies all the PredicateFilter functions in funcs. It returns false as soon as it finds a function in funcs that the element does not satisfy.

Parameters:

  • funcs: A slice of PredicateFilter functions.

Returns:

  • PredicateFilter: A PredicateFilter function that checks if a element satisfies all the PredicateFilter functions in funcs.

func Union

func Union[T any](funcs ...PredicateFilter[T]) PredicateFilter[T]

Union returns a PredicateFilter function that checks if an element satisfies at least one of the PredicateFilter functions in funcs. It returns true as soon as it finds a function in funcs that the element satisfies.

Parameters:

  • funcs: A slice of PredicateFilter functions.

Returns:

  • PredicateFilter: A PredicateFilter function that checks if a element satisfies at least one of the PredicateFilter functions in funcs.

Jump to

Keyboard shortcuts

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