fl

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 1 Imported by: 0

README

fl

CI

A functional utility library for Go.

Example

import (
    "fmt"

    "github.com/ee2500/fl"
)

func main() {
    result := fl.Filter([]int{1, 2, 3, 4, 5, 6}, fl.Even)
    fmt.Println(result) // []int{2, 4, 6}
}

Documentation

See the documentation.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Even

func Even[T constraints.Integer](n T) bool

Check if n is even.

func Fill

func Fill[T any](s []T, v T) []T

Fill applies a value fills the elements of the slice.

func Filter

func Filter[T any](s []T, fn func(T) bool) []T

The Filter function is a higher-order function in programming that takes an input slice and applies the s to each element of the slice, deciding whether to keep or discard the element based on the truth value of the function's return. It returns a new slice of the filtered results. It allows for easy filtering of data without the need for explicit iteration or looping over the original slice.

func ForEach

func ForEach[T any](s []T, f func(int, T))

ForEach applies the function f to each element of the s. The function f takes an integer as its argument and returns nothing.

func Map

func Map[T any](s []T, fn func(T) T) []T

The Map function is a higher-order function in programming that takes an input slice and applies the s to each element of the slice, returning a new slice of the results. It allows for easy transformation of data without the need for explicit iteration or looping over the original slice.

func Nth

func Nth[T any](index int, elems []T) T

Give a value from the slice.

func Odd

func Odd[T constraints.Integer](n T) bool

Check if n is odd.

func Range

func Range[T constraints.Integer](start, end T) []T

Range applies give a slice from start to end.

func Reduce

func Reduce[T, M any](s []T, f func(M, T) M, initValue M) M

The Reduce function is a higher-order function in programming that takes an input slice and applies the s to the elements of the slice in a cumulative way, reducing the slice to a single value. It iteratively applies the function to the elements of the slice, accumulating the result at each step, until a single value is obtained. It allows for easy aggregation of data without the need for explicit iteration or looping over the original slice.

func Sum

func Sum[T constraints.Float | constraints.Integer](nums []T) T

Give the sum of the slice.

func Uniq

func Uniq[T comparable](s []T) []T

Range applies every element of the slice is unique.

Types

This section is empty.

Jump to

Keyboard shortcuts

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