package generic

import "github.com/IBM/fp-go/array/generic"

Index

Functions

func Any

func Any[AS ~[]A, PRED ~func(A) bool, A any](pred PRED) func(AS) bool

Any tests if any of the elements in the array matches the predicate

func AnyWithIndex

func AnyWithIndex[AS ~[]A, PRED ~func(int, A) bool, A any](pred PRED) func(AS) bool

AnyWithIndex tests if any of the elements in the array matches the predicate

func Ap

func Ap[BS ~[]B, ABS ~[]func(A) B, AS ~[]A, B, A any](fa AS) func(ABS) BS

func ApS

func ApS[GS1 ~[]S1, GS2 ~[]S2, GT ~[]T, S1, S2, T any](
	setter func(T) func(S1) S2,
	fa GT,
) func(GS1) GS2

ApS attaches a value to a context [S1] to produce a context [S2] by considering the context and the value concurrently

func Append

func Append[GA ~[]A, A any](as GA, a A) GA

func Bind

func Bind[GS1 ~[]S1, GS2 ~[]S2, GT ~[]T, S1, S2, T any](
	setter func(T) func(S1) S2,
	f func(S1) GT,
) func(GS1) GS2

Bind attaches the result of a computation to a context [S1] to produce a context [S2]

func BindTo

func BindTo[GS1 ~[]S1, GT ~[]T, S1, T any](
	setter func(T) S1,
) func(GT) GS1

BindTo initializes a new state [S1] from a value [T]

func Chain

func Chain[AS ~[]A, BS ~[]B, A, B any](f func(A) BS) func(AS) BS

func Clone

func Clone[AS ~[]A, A any](f func(A) A) func(as AS) AS

func Copy

func Copy[AS ~[]A, A any](b AS) AS

func Do

func Do[GS ~[]S, S any](
	empty S,
) GS

Bind creates an empty context of type [S] to be used with the Bind operation

func Empty

func Empty[GA ~[]A, A any]() GA

func Filter

func Filter[AS ~[]A, PRED ~func(A) bool, A any](pred PRED) func(AS) AS

func FilterChain

func FilterChain[GA ~[]A, GB ~[]B, A, B any](f func(a A) O.Option[GB]) func(GA) GB

func FilterMap

func FilterMap[GA ~[]A, GB ~[]B, A, B any](f func(A) O.Option[B]) func(GA) GB

func FilterMapWithIndex

func FilterMapWithIndex[GA ~[]A, GB ~[]B, A, B any](f func(int, A) O.Option[B]) func(GA) GB

func FilterWithIndex

func FilterWithIndex[AS ~[]A, PRED ~func(int, A) bool, A any](pred PRED) func(AS) AS

func FindFirst

func FindFirst[AS ~[]A, PRED ~func(A) bool, A any](pred PRED) func(AS) O.Option[A]

FindFirst finds the first element which satisfies a predicate (or a refinement) function

func FindFirstMap

func FindFirstMap[AS ~[]A, PRED ~func(A) O.Option[B], A, B any](pred PRED) func(AS) O.Option[B]

FindFirstMap finds the first element returned by an [O.Option] based selector function

func FindFirstMapWithIndex

func FindFirstMapWithIndex[AS ~[]A, PRED ~func(int, A) O.Option[B], A, B any](pred PRED) func(AS) O.Option[B]

FindFirstMapWithIndex finds the first element returned by an [O.Option] based selector function

func FindFirstWithIndex

func FindFirstWithIndex[AS ~[]A, PRED ~func(int, A) bool, A any](pred PRED) func(AS) O.Option[A]

FindFirstWithIndex finds the first element which satisfies a predicate (or a refinement) function

func FindLast

func FindLast[AS ~[]A, PRED ~func(A) bool, A any](pred PRED) func(AS) O.Option[A]

FindLast finds the first element which satisfies a predicate (or a refinement) function

func FindLastMap

func FindLastMap[AS ~[]A, PRED ~func(A) O.Option[B], A, B any](pred PRED) func(AS) O.Option[B]

FindLastMap finds the first element returned by an [O.Option] based selector function

func FindLastMapWithIndex

func FindLastMapWithIndex[AS ~[]A, PRED ~func(int, A) O.Option[B], A, B any](pred PRED) func(AS) O.Option[B]

FindLastMapWithIndex finds the first element returned by an [O.Option] based selector function

func FindLastWithIndex

func FindLastWithIndex[AS ~[]A, PRED ~func(int, A) bool, A any](pred PRED) func(AS) O.Option[A]

FindLastWithIndex finds the first element which satisfies a predicate (or a refinement) function

func First

func First[GA ~[]A, A any](as GA) O.Option[A]

func Flap

func Flap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](a A) func(GFAB) GB

func Flatten

func Flatten[GAA ~[]GA, GA ~[]A, A any](mma GAA) GA

func Fold

func Fold[AS ~[]A, A any](m M.Monoid[A]) func(AS) A

func FoldMap

func FoldMap[AS ~[]A, A, B any](m M.Monoid[B]) func(func(A) B) func(AS) B

func FoldMapWithIndex

func FoldMapWithIndex[AS ~[]A, A, B any](m M.Monoid[B]) func(func(int, A) B) func(AS) B

func From

func From[GA ~[]A, A any](data ...A) GA

From constructs an array from a set of variadic arguments

func Head[GA ~[]A, A any](as GA) O.Option[A]

func IsEmpty

func IsEmpty[AS ~[]A, A any](as AS) bool

func IsNil

func IsNil[GA ~[]A, A any](as GA) bool

func IsNonNil

func IsNonNil[GA ~[]A, A any](as GA) bool

func Last

func Last[GA ~[]A, A any](as GA) O.Option[A]

func Let

func Let[GS1 ~[]S1, GS2 ~[]S2, S1, S2, T any](
	key func(T) func(S1) S2,
	f func(S1) T,
) func(GS1) GS2

Let attaches the result of a computation to a context [S1] to produce a context [S2]

func LetTo

func LetTo[GS1 ~[]S1, GS2 ~[]S2, S1, S2, B any](
	key func(B) func(S1) S2,
	b B,
) func(GS1) GS2

LetTo attaches the a value to a context [S1] to produce a context [S2]

func Lookup

func Lookup[GA ~[]A, A any](idx int) func(GA) O.Option[A]

func MakeBy

func MakeBy[AS ~[]A, F ~func(int) A, A any](n int, f F) AS

MakeBy returns a `Array` of length `n` with element `i` initialized with `f(i)`.

func Map

func Map[GA ~[]A, GB ~[]B, A, B any](f func(a A) B) func(GA) GB

func MapWithIndex

func MapWithIndex[GA ~[]A, GB ~[]B, A, B any](f func(int, A) B) func(GA) GB

func Match

func Match[AS ~[]A, A, B any](onEmpty func() B, onNonEmpty func(AS) B) func(AS) B

func MatchLeft

func MatchLeft[AS ~[]A, A, B any](onEmpty func() B, onNonEmpty func(A, AS) B) func(AS) B

func Monad

func Monad[A, B any, GA ~[]A, GB ~[]B, GAB ~[]func(A) B]() monad.Monad[A, B, GA, GB, GAB]

Monad implements the monadic operations for an array

func MonadAp

func MonadAp[BS ~[]B, ABS ~[]func(A) B, AS ~[]A, B, A any](fab ABS, fa AS) BS

func MonadChain

func MonadChain[AS ~[]A, BS ~[]B, A, B any](fa AS, f func(a A) BS) BS

func MonadFilterMap

func MonadFilterMap[GA ~[]A, GB ~[]B, A, B any](fa GA, f func(A) O.Option[B]) GB

func MonadFilterMapWithIndex

func MonadFilterMapWithIndex[GA ~[]A, GB ~[]B, A, B any](fa GA, f func(int, A) O.Option[B]) GB

func MonadFlap

func MonadFlap[FAB ~func(A) B, GFAB ~[]FAB, GB ~[]B, A, B any](fab GFAB, a A) GB

func MonadMap

func MonadMap[GA ~[]A, GB ~[]B, A, B any](as GA, f func(a A) B) GB

func MonadMapWithIndex

func MonadMapWithIndex[GA ~[]A, GB ~[]B, A, B any](as GA, f func(int, A) B) GB

func MonadPartition

func MonadPartition[GA ~[]A, A any](as GA, pred func(A) bool) tuple.Tuple2[GA, GA]

func MonadReduce

func MonadReduce[GA ~[]A, A, B any](fa GA, f func(B, A) B, initial B) B

func MonadReduceRight

func MonadReduceRight[GA ~[]A, A, B any](fa GA, f func(A, B) B, initial B) B

func MonadReduceRightWithIndex

func MonadReduceRightWithIndex[GA ~[]A, A, B any](fa GA, f func(int, A, B) B, initial B) B

func MonadReduceWithIndex

func MonadReduceWithIndex[GA ~[]A, A, B any](fa GA, f func(int, B, A) B, initial B) B

func Of

func Of[GA ~[]A, A any](value A) GA

Of constructs a single element array

func Partition

func Partition[GA ~[]A, A any](pred func(A) bool) func(GA) tuple.Tuple2[GA, GA]

func Prepend

func Prepend[ENDO ~func(AS) AS, AS []A, A any](head A) ENDO

func Push

func Push[ENDO ~func(GA) GA, GA ~[]A, A any](a A) ENDO

func Reduce

func Reduce[GA ~[]A, A, B any](f func(B, A) B, initial B) func(GA) B

func ReduceRight

func ReduceRight[GA ~[]A, A, B any](f func(A, B) B, initial B) func(GA) B

func ReduceRightWithIndex

func ReduceRightWithIndex[GA ~[]A, A, B any](f func(int, A, B) B, initial B) func(GA) B

func ReduceWithIndex

func ReduceWithIndex[GA ~[]A, A, B any](f func(int, B, A) B, initial B) func(GA) B

func Replicate

func Replicate[AS ~[]A, A any](n int, a A) AS

func Size

func Size[GA ~[]A, A any](as GA) int

func Slice

func Slice[AS ~[]A, A any](start int, end int) func(AS) AS

func SliceRight

func SliceRight[AS ~[]A, A any](start int) func(AS) AS

func Sort

func Sort[GA ~[]T, T any](ord O.Ord[T]) func(ma GA) GA

Sort implements a stable sort on the array given the provided ordering

func SortBy

func SortBy[GA ~[]T, GO ~[]O.Ord[T], T any](ord GO) func(ma GA) GA

SortBy implements a stable sort on the array given the provided ordering

func SortByKey

func SortByKey[GA ~[]T, K, T any](ord O.Ord[K], f func(T) K) func(ma GA) GA

SortByKey implements a stable sort on the array given the provided ordering on an extracted key

func StrictUniq

func StrictUniq[AS ~[]A, A comparable](as AS) AS

StrictUniq converts an array of arbitrary items into an array or unique items where uniqueness is determined by the built-in uniqueness constraint

func Tail

func Tail[GA ~[]A, A any](as GA) O.Option[GA]

func Uniq

func Uniq[AS ~[]A, PRED ~func(A) K, A any, K comparable](f PRED) func(as AS) AS

Uniq converts an array of arbitrary items into an array or unique items where uniqueness is determined based on a key extractor function

func Unzip

func Unzip[AS ~[]A, BS ~[]B, CS ~[]T.Tuple2[A, B], A, B any](cs CS) T.Tuple2[AS, BS]

Unzip is the function is reverse of Zip. Takes an array of pairs and return two corresponding arrays

func UpsertAt

func UpsertAt[GA ~[]A, A any](a A) func(GA) GA

func Zip

func Zip[AS ~[]A, BS ~[]B, CS ~[]T.Tuple2[A, B], A, B any](fb BS) func(AS) CS

Zip takes two arrays and returns an array of corresponding pairs. If one input array is short, excess elements of the longer array are discarded

func ZipWith

func ZipWith[AS ~[]A, BS ~[]B, CS ~[]C, FCT ~func(A, B) C, A, B, C any](fa AS, fb BS, f FCT) CS

ZipWith applies a function to pairs of elements at the same index in two arrays, collecting the results in a new array. If one input array is short, excess elements of the longer array are discarded.

Source Files

any.go array.go bind.go find.go monad.go sort.go uniq.go zip.go

Version
v1.0.151 (latest)
Published
Nov 23, 2024
Platform
linux/amd64
Imports
12 packages
Last checked
4 months ago

Tools for package owners.