slicefunk

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 0 Imported by: 13

README

slicefunk

Providing some collection functions in go

Example usage:

package main

import (
    "fmt"

    sf "github.com/sa-/slicefunk"
)

func main() {
    original := []int{1, 2, 3, 4, 5}
    newArray := sf.Map(original, func(item int) int { return item + 1 })
    newArray = sf.Map(newArray, func(item int) int { return item * 3 })
    newArray = sf.Filter(newArray, func(item int) bool { return item%2 == 0 })
    fmt.Println(newArray)
    
    duplicates := []string{"cat", "dog", "bird", "cat"}
    deduped := sf.Unique(duplicates)
    fmt.Println(deduped)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

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

func FlatMap added in v0.1.4

func FlatMap[T, U any](s [][]T, f func(T) U) []U

func Flatten added in v0.1.4

func Flatten[T any](s [][]T) []T

func Map

func Map[T, U any](s []T, f func(T) U) []U

func Unique added in v0.1.3

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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