tools

package
v0.1.2-0...-95afe0f Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 3 Imported by: 0

README

tools

import "github.com/ShauryaAg/go-functools/tools"

Index

func ArrayEquals

func ArrayEquals[T comparable](a []T, b []T) bool

ArrayEquals returns true if 'a' and 'b' are equal.

func CopyWithin

func CopyWithin[T any](slice []T, target int, start int, end int) []T

CopyWithin copies slice[start:end] to slice[target:target+(start-end)]

func DefaultCompare

func DefaultCompare[T constraints.Ordered](a, b T) bool

Default compare function for Sort[T] with Ordered type constraint.

func DefaultCompareC

func DefaultCompareC[T utils.Comparable[T]](a, b T) bool

Default compare function for Sort[T] with Comparable type constraint.

Comparable type constraint is a custom constraint that checks the type to contain a Compare() method.

func Every

func Every[T any](slice []T, callback func(T) bool) bool

Every returns true if all elements in the 'slice' satisfies the test implemented by the 'callback' function.

func Fill

func Fill[T any](slice []T, value T, start int, end int) []T

Fill replaces the elements of the 'slice[start:end]' with 'value'.

func Filter

func Filter[T any](slice []T, callback func(T) bool) []T

Filter finds all the elements in the 'slice' that satisfy the 'callback' function.

func Find

func Find[T any](slice []T, callback func(T) bool) T

Find returns first element in 'slice' that satisfies the given 'callback' function.

func FindIndex

func FindIndex[T any](slice []T, callback func(T) bool) int

Find returns first element index in 'slice' that satisfies the given 'callback' function.

func ForEach

func ForEach[T any](slice []T, callback func(T))

ForEach runs 'callback' function for each element in the 'slice'.

func Includes

func Includes[T comparable](slice []T, value T) bool

Includes returns true if the 'slice' includes the given 'value', otherwise false.

func Join

func Join[T any](slice []T, separator string) string

Join returns a string of the 'slice' elements concatenated with 'separator'.

func Map

func Map[T any, U any](slice []T, callback func(T) U) []U

Map applies 'callback' function to all the elements in 'slice' and returns the result.

func Reduce

func Reduce[T any, U any](slice []T, callback func(U, T) U, initial U) U

Reduce runs a function for each element in 'slice', and reduces it into a single value, using the given 'callback' function and 'initial' value.

func Reverse

func Reverse[T any](slice []T) []T

Reverse turns the 'slice' into reversed order.

func Shift

func Shift[T any](slice []T) []T

Shift removes the first element from the 'slice' and returns it.

func Some

func Some[T any](slice []T, callback func(T) bool) bool

Some returns true if some of the element(s) in the 'slice' satisfy the given 'callback' function, otherwise false.

func Sort

func Sort[T any](slice []T, compareFn func(T, T) bool) []T

Sort the 'slice' using the 'compareFn' function.

func Unshift

func Unshift[T any](slice []T, elems ...T) []T

Unshift adds 'elems' to the beginning of the 'slice' and returns the new 'slice'.

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayEquals

func ArrayEquals[T comparable](a []T, b []T) bool

ArrayEquals returns true if 'a' and 'b' are equal.

func CopyWithin

func CopyWithin[T any](slice []T, target int, start int, end int) []T

CopyWithin copies slice[start:end] to slice[target:target+(start-end)]

func DefaultCompare

func DefaultCompare[T constraints.Ordered](a, b T) bool

Default compare function for Sort[T] with Ordered type constraint.

func DefaultCompareC

func DefaultCompareC[T utils.Comparable[T]](a, b T) bool

Default compare function for Sort[T] with Comparable type constraint.

Comparable type constraint is a custom constraint that checks the type to contain a Compare() method.

func Every

func Every[T any](slice []T, callback func(T) bool) bool

Every returns true if all elements in the 'slice' satisfies the test implemented by the 'callback' function.

func Fill

func Fill[T any](slice []T, value T, start int, end int) []T

Fill replaces the elements of the 'slice[start:end]' with 'value'.

func Filter

func Filter[T any](slice []T, callback func(T) bool) []T

Filter finds all the elements in the 'slice' that satisfy the 'callback' function.

func Find

func Find[T any](slice []T, callback func(T) bool) T

Find returns first element in 'slice' that satisfies the given 'callback' function.

func FindIndex

func FindIndex[T any](slice []T, callback func(T) bool) int

Find returns first element index in 'slice' that satisfies the given 'callback' function.

func ForEach

func ForEach[T any](slice []T, callback func(T))

ForEach runs 'callback' function for each element in the 'slice'.

func Includes

func Includes[T comparable](slice []T, value T) bool

Includes returns true if the 'slice' includes the given 'value', otherwise false.

func Join

func Join[T any](slice []T, separator string) string

Join returns a string of the 'slice' elements concatenated with 'separator'.

func Map

func Map[T any, U any](slice []T, callback func(T) U) []U

Map applies 'callback' function to all the elements in 'slice' and returns the result.

func Reduce

func Reduce[T any, U any](slice []T, callback func(U, T) U, initial U) U

Reduce runs a function for each element in 'slice', and reduces it into a single value, using the given 'callback' function and 'initial' value.

func Reverse

func Reverse[T any](slice []T) []T

Reverse turns the 'slice' into reversed order.

func Shift

func Shift[T any](slice []T) []T

Shift removes the first element from the 'slice' and returns it.

func Some

func Some[T any](slice []T, callback func(T) bool) bool

Some returns true if some of the element(s) in the 'slice' satisfy the given 'callback' function, otherwise false.

func Sort

func Sort[T any](slice []T, compareFn func(T, T) bool) []T

Sort the 'slice' using the 'compareFn' function.

func Unshift

func Unshift[T any](slice []T, elems ...T) []T

Unshift adds 'elems' to the beginning of the 'slice' and returns the new 'slice'.

Types

This section is empty.

Jump to

Keyboard shortcuts

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