MapExt

package
v0.2.38 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapFilter

func MapFilter[T comparable, E any](S map[T]E, filter PredicateFilter[T, E]) map[T]E

MapFilter is a function that iterates over the

Parameters:

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

Returns:

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

Behaviors:

  • An element is said to satisfy the filter function if the function returns true for that element.
  • If S is empty, it returns a non-nil empty map.
  • If filter is nil, it returns S as is

Types

type PredicateFilter

type PredicateFilter[T comparable, E any] func(T, E) bool

PredicateFilter is a type that defines a map filter function.

Parameters:

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

Returns:

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

func Intersect

func Intersect[T comparable, E any](funcs ...PredicateFilter[T, E]) PredicateFilter[T, E]

Intersect returns a PredicateFilter function that checks if an element satisfies all the PredicateFilter functions in funcs.

Parameters:

  • funcs: A map of PredicateFilter functions.

Returns:

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

Behaviors:

  • It returns false as soon as it finds a function in funcs that the element does not satisfy.
  • If no functions are provided, it returns a function that always returns true.

func Union

func Union[T comparable, E any](funcs ...PredicateFilter[T, E]) PredicateFilter[T, E]

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 map of PredicateFilter functions.

Returns:

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

Behaviors:

  • It returns true as soon as it finds a function in funcs that the element satisfies.
  • If no functions are provided, it returns a function that always returns false.

Jump to

Keyboard shortcuts

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