fp

package module
v0.0.0-...-762a710 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 0 Imported by: 0

README

fp-go

Go Reference Go Report codecov

Fp-go is a collection of Functional Programming helpers powered by Golang 1.18+ generics.

Inspired by

Contents

Install

Requires go 1.18+

go get github.com/repeale/fp-go

Features

Currying

By default! Data last!

func isPositive(x int) bool {
	return x > 0
}

func main() {
    filterPositive := fp.Filter(isPositive)
    numbers := []int{1, 2, 3, 4, 5}

    positives := filterPositive(numbers)
}
Variations

Variations allows you to get different parameters in the callback function so that you get only only what is really needed.

Default
WithIndex
WithSlice

Default

Only the current item is available:

fp.Map[int, string](func(x int) { ... })
WithIndex

Current element and index are available:

fp.MapWithIndex[int, string](func(x int, i int) { ... })
WithSlice

Current element, index and the whole slice are available:

fp.MapWithSlice[int, string](func(x int, i int, xs: []int) { ... })

Helpers

Every

Determines whether all the members of an array satisfy the specified test.

Variations EveryWithIndex and EveryWithSlice

fp.Every(func(x int) bool { return x > 0 })([]int{1, 2, 3})

// => true
Filter

Returns the elements of an array that meet the condition specified in a callback function.

Variations FilterWithIndex and FilterWithSlice

fp.Filter(func(x int) bool { return x > 0 })([]int{-1, 2, -3, 4})

// => []int{2, 4}
Flat

Returns a new array with all sub-array elements concatenated into it.

fp.Flat([][]int{{1, 2}, {3, 4}})

// => []int{1, 2, 3, 4}
FlatMap

Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat.

Variations FlatMapWithIndex and FlatMapWithSlice

fp.FlatMap(func(x int) []int { return []int{x, x} })([]int{1, 2})

// => []int{1, 1, 2, 2}
Map

Calls a defined callback function on each element of an array, and returns an array that contains the results.

Variations MapWithIndex and MapWithSlice

fp.Map(func(x int64) string {
    return strconv.FormatInt(x, 10)
})([]int64{1, 2, 3})

// => []string{"1", "2", "3", "4"}
Reduce

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Variations ReduceWithIndex and ReduceWithSlice

fp.Reduce(func(acc int, curr int) int { return acc + curr }, 0)([]int{1, 2, 3})

// => 6
Some

Determines whether the specified callback function returns true for any element of an array.

Variations SomeWithIndex and SomeWithSlice

fp.Some(func(x int) bool { return x < 0 })([]int{1, 2, 3})

// => false

Compose

Performs right-to-left function composition.

Variations Compose2 to Compose16 stating the number of functions you are going to compose.

func isPositive(x int) bool {
	return x > 0
}

func sumTwo(x int) int {
	return x + 2
}

Compose2(fp.Filter(isPositive), fp.Map(sumTwo))([]int{1, 2, 3, -1})

// => []int{3,4,5,1}
Pipe

Performs left-to-right function composition.

Variations Pipe2 to Pipe16 stating the number of functions you are going to compose.

func isPositive(x int) bool {
	return x > 0
}

func sumTwo(x int) int {
	return x + 2
}

Pipe2(fp.Filter(isPositive), fp.Map(sumTwo))([]int{1, 2, 3, -1})

// => []int{3,4,5}
Curry

Allow to transfrom a function that receives a certain amount of params in single functions that take one single param each.

Variations Curry2 to Curry16 stating the number of params will be curried individually.

curryedSum := Curry2(func(a int, b int) int { return a + b })
curryedSum(1)(2)

Structs

Option

Option represents encapsulation of an optional value, it might be used as the return type of functions which may or may not return a meaningful value when they are applied.

Option exports Some, None, IsSome, IsNone, Chain, Exists, Flatten, FromError, FromErrorFn, FromPredicate, GetOrElse, Map, Match.

Either

Either represent a value that can have two possible types. It is common to see Either used to represent a success value Right or a failure value Left, although that doesn't have to be the case. An instance of Either is either an instance of Left or Right.

Either exports Left, Right, IsLeft, IsRight, Exists, Flatten, FromError, FromErrorFn, FromOption, FromPredicate, GetOrElse, Map, MapLeft, Match,

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compose10

func Compose10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn10 func(T10) R, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 10 functions

func Compose11

func Compose11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn11 func(T11) R, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 11 functions

func Compose12

func Compose12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn12 func(T12) R, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 12 functions

func Compose13

func Compose13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn13 func(T13) R, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 13 functions

func Compose14

func Compose14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn14 func(T14) R, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 14 functions

func Compose15

func Compose15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn15 func(T15) R, fn14 func(T14) T15, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 15 functions

func Compose16

func Compose16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](fn16 func(T16) R, fn15 func(T15) T16, fn14 func(T14) T15, fn13 func(T13) T14, fn12 func(T12) T13, fn11 func(T11) T12, fn10 func(T10) T11, fn9 func(T9) T10, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 16 functions

func Compose2

func Compose2[T1, T2, R any](fn2 func(T2) R, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of two functions

func Compose3

func Compose3[T1, T2, T3, R any](fn3 func(T3) R, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of three functions

func Compose4

func Compose4[T1, T2, T3, T4, R any](fn4 func(T4) R, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of four functions

func Compose5

func Compose5[T1, T2, T3, T4, T5, R any](fn5 func(T5) R, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 5 functions

func Compose6

func Compose6[T1, T2, T3, T4, T5, T6, R any](fn6 func(T6) R, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 6 functions

func Compose7

func Compose7[T1, T2, T3, T4, T5, T6, T7, R any](fn7 func(T7) R, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 7 functions

func Compose8

func Compose8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn8 func(T8) R, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 8 functions

func Compose9

func Compose9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn9 func(T9) R, fn8 func(T8) T9, fn7 func(T7) T8, fn6 func(T6) T7, fn5 func(T5) T6, fn4 func(T4) T5, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R

Performs right-to-left function composition of 9 functions

func Converge2

func Converge2[R1, R2, R, T any](fc func(R1, R2) R, f1 func(T) R1, f2 func(T) R2) func(T) R

Apply converge of 2 branch functions

func Curry10

func Curry10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) R

Allow to transform a function that receives 10 params in a sequence of unary functions

func Curry11

func Curry11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) R

Allow to transform a function that receives 11 params in a sequence of unary functions

func Curry12

func Curry12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) R

Allow to transform a function that receives 12 params in a sequence of unary functions

func Curry13

func Curry13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) R

Allow to transform a function that receives 13 params in a sequence of unary functions

func Curry14

func Curry14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) func(T14) R

Allow to transform a function that receives 14 params in a sequence of unary functions

func Curry15

func Curry15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) func(T14) func(T15) R

Allow to transform a function that receives 15 params in a sequence of unary functions

func Curry16

func Curry16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) func(T10) func(T11) func(T12) func(T13) func(T14) func(T15) func(T16) R

Allow to transform a function that receives 16 params in a sequence of unary functions

func Curry2

func Curry2[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R

Allow to transform a function that receives 2 params in a sequence of unary functions

func Curry3

func Curry3[T1, T2, T3, R any](fn func(T1, T2, T3) R) func(T1) func(T2) func(T3) R

Allow to transform a function that receives 3 params in a sequence of unary functions

func Curry4

func Curry4[T1, T2, T3, T4, R any](fn func(T1, T2, T3, T4) R) func(T1) func(T2) func(T3) func(T4) R

Allow to transform a function that receives 4 params in a sequence of unary functions

func Curry5

func Curry5[T1, T2, T3, T4, T5, R any](fn func(T1, T2, T3, T4, T5) R) func(T1) func(T2) func(T3) func(T4) func(T5) R

Allow to transform a function that receives 5 params in a sequence of unary functions

func Curry6

func Curry6[T1, T2, T3, T4, T5, T6, R any](fn func(T1, T2, T3, T4, T5, T6) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) R

Allow to transform a function that receives 6 params in a sequence of unary functions

func Curry7

func Curry7[T1, T2, T3, T4, T5, T6, T7, R any](fn func(T1, T2, T3, T4, T5, T6, T7) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) R

Allow to transform a function that receives 7 params in a sequence of unary functions

func Curry8

func Curry8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) R

Allow to transform a function that receives 8 params in a sequence of unary functions

func Curry9

func Curry9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn func(T1, T2, T3, T4, T5, T6, T7, T8, T9) R) func(T1) func(T2) func(T3) func(T4) func(T5) func(T6) func(T7) func(T8) func(T9) R

Allow to transform a function that receives 9 params in a sequence of unary functions

func Every

func Every[T any](predicate func(T) bool) func([]T) bool

Determines whether all the members of an array satisfy the specified test.

func EveryWithIndex

func EveryWithIndex[T any](predicate func(T, int) bool) func([]T) bool

See Every but callback receives index of element.

func EveryWithSlice

func EveryWithSlice[T any](predicate func(T, int, []T) bool) func([]T) bool

Like Every but callback receives index of element and the whole array.

func Filter

func Filter[T any](predicate func(T) bool) func([]T) []T

Returns the elements of an array that meet the condition specified in a callback function.

func FilterWithIndex

func FilterWithIndex[T any](predicate func(T, int) bool) func([]T) []T

See Filter but callback receives index of element.

func FilterWithSlice

func FilterWithSlice[T any](predicate func(T, int, []T) bool) func([]T) []T

Like Filter but callback receives index of element and the whole array.

func Flat

func Flat[T any](xs [][]T) []T

Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.

func FlatMap

func FlatMap[T any, R any](callback func(T) []R) func([]T) []R

Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.

func FlatMapWithIndex

func FlatMapWithIndex[T any, R any](callback func(T, int) []R) func([]T) []R

See FlatMap but callback receives index of element.

func FlatMapWithSlice

func FlatMapWithSlice[T any, R any](callback func(T, int, []T) []R) func([]T) []R

Like FlatMap but callback receives index of element and the whole array.

func Map

func Map[T any, R any](callback func(T) R) func([]T) []R

Calls a defined callback function on each element of an array, and returns an array that contains the results.

func MapWithIndex

func MapWithIndex[T any, R any](callback func(T, int) R) func([]T) []R

See Map but callback receives index of element.

func MapWithSlice

func MapWithSlice[T any, R any](callback func(T, int, []T) R) func([]T) []R

Like Map but callback receives index of element and the whole array.

func Pipe10

func Pipe10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) R) func(T1) R

Performs left-to-right function composition of 10 functions

func Pipe11

func Pipe11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) T11, fn11 func(T11) R) func(T1) R

Performs left-to-right function composition of 11 functions

func Pipe12

func Pipe12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) T11, fn11 func(T11) T12, fn12 func(T12) R) func(T1) R

Performs left-to-right function composition of 12 functions

func Pipe13

func Pipe13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) T11, fn11 func(T11) T12, fn12 func(T12) T13, fn13 func(T13) R) func(T1) R

Performs left-to-right function composition of 13 functions

func Pipe14

func Pipe14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) T11, fn11 func(T11) T12, fn12 func(T12) T13, fn13 func(T13) T14, fn14 func(T14) R) func(T1) R

Performs left-to-right function composition of 14 functions

func Pipe15

func Pipe15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) T11, fn11 func(T11) T12, fn12 func(T12) T13, fn13 func(T13) T14, fn14 func(T14) T15, fn15 func(T15) R) func(T1) R

Performs left-to-right function composition of 15 functions

func Pipe16

func Pipe16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) T10, fn10 func(T10) T11, fn11 func(T11) T12, fn12 func(T12) T13, fn13 func(T13) T14, fn14 func(T14) T15, fn15 func(T15) T16, fn16 func(T16) R) func(T1) R

Performs left-to-right function composition of 16 functions

func Pipe2

func Pipe2[T1, T2, R any](fn1 func(T1) T2, fn2 func(T2) R) func(T1) R

Performs left-to-right function composition of two functions

func Pipe3

func Pipe3[T1, T2, T3, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) R) func(T1) R

Performs left-to-right function composition of three functions

func Pipe4

func Pipe4[T1, T2, T3, T4, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) R) func(T1) R

Performs left-to-right function composition of four functions

func Pipe5

func Pipe5[T1, T2, T3, T4, T5, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) R) func(T1) R

Performs left-to-right function composition of five functions

func Pipe6

func Pipe6[T1, T2, T3, T4, T5, T6, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) R) func(T1) R

Performs left-to-right function composition of 6 functions

func Pipe7

func Pipe7[T1, T2, T3, T4, T5, T6, T7, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) R) func(T1) R

Performs left-to-right function composition of 7 functions

func Pipe8

func Pipe8[T1, T2, T3, T4, T5, T6, T7, T8, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) R) func(T1) R

Performs left-to-right function composition of 8 functions

func Pipe9

func Pipe9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) T5, fn5 func(T5) T6, fn6 func(T6) T7, fn7 func(T7) T8, fn8 func(T8) T9, fn9 func(T9) R) func(T1) R

Performs left-to-right function composition of 9 functions

func Reduce

func Reduce[T any, R any](callback func(R, T) R, acc R) func([]T) R

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

func ReduceWithIndex

func ReduceWithIndex[T any, R any](callback func(R, T, int) R, acc R) func([]T) R

See Reduce but callback receives index of element.

func ReduceWithSlice

func ReduceWithSlice[T any, R any](callback func(R, T, int, []T) R, acc R) func([]T) R

Like Reduce but callback receives index of element and the whole array.

func Some

func Some[T any](predicate func(T) bool) func([]T) bool

Determines whether the specified callback function returns true for any element of an array.

func SomeWithIndex

func SomeWithIndex[T any](predicate func(T, int) bool) func([]T) bool

See Some but callback receives index of element.

func SomeWithSlice

func SomeWithSlice[T any](predicate func(T, int, []T) bool) func([]T) bool

Like Some but callback receives index of element and the whole array.

Types

type Lazy

type Lazy[T any] func() T

Callback function that returns a specific value type

type LazyVal

type LazyVal[T any] func(x T) T

Callback function that takes an argument and return a value of the same type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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