funktors

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 0 Imported by: 1

README

Funktors

A high order function library for applying various array methods like map, reduce, filters etc, using generics.

Currently supports:

  • Foreach
  • Map
  • Filter
  • Concat
  • Fill
  • GroupBy
  • Reduce
  • Find
  • Sum
  • Every

Example

For eg. given an array for strings, filter if the string contain the word "test". With funktors, you can solve it as follows:

    input := []string{"test123", "123all", "testvalue"}
	values := funktors.Filter(input, func(index int, a string) bool {
		return strings.Contains(a, "test")
	})
	log.Println(values)
}

Without funktors, it would look something like this:

    input := []string{"test123", "123all", "testvalue"}
    var output []string{}
        
   for _, v := range input {
        if strings.Contains(v, "test") {
            output = append(output, v)
        }
   }
   log.Println(output)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat

func Concat[V any](v1 []V, v2 []V) []V

func Contains

func Contains[V any](v []V, a func(index int, v1 V) bool) bool

func Every

func Every[V any](v []V, a func(index int, v1 V) bool) bool

func Fill

func Fill[V any](v []V, valueToBeFilled V, pos1 int, pos2 int) bool

func Filter

func Filter[V any](v []V, a func(index int, v1 V) bool) []V

func FindAll

func FindAll[V any](v []V, a func(index int, v1 V) bool) []V

func FindAny

func FindAny[V any](v []V, a func(index int, v1 V) bool) *V

func ForEach

func ForEach[V any](v []V, a func(index int, v1 V))

func GroupBy

func GroupBy[T comparable, V any](v []V, a func(v1 V) map[T]V) map[T][]V

func Map

func Map[T any, V any](v []V, a func(index int, v1 V) T) []T

func Reduce

func Reduce[T comparable, V any](v []V, a func(v1 V) map[T]V) map[T]V

func SplitN added in v0.0.6

func SplitN[V any](v []V, n int) [][]V

func Sum

func Sum[V int64 | int32 | int | float64 | float32](v []V) V

Types

This section is empty.

Jump to

Keyboard shortcuts

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