slicez

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 1 Imported by: 0

README

gopherz

ezpkg.io/slicez

PkgGoDev GitHub License version

Package slicez extends the standard library slices with additional functions.

Installation

go get -u ezpkg.io/slicez@v0.1.0

Examples

codes := slicez.MapFunc([]int{1, 2, 3}, func(i int) string {
    return fmt.Sprintf("CODE(%d)", i)
})
fmt.Println(codes)

About ezpkg.io

As I work on various Go projects, I often find myself creating utility functions, extending existing packages, or developing packages to solve specific problems. Moving from one project to another, I usually have to copy or rewrite these solutions. So I created this repository to have all these utilities and packages in one place. Hopefully, you'll find them useful as well.

For more information, see the main repository.

Author

Oliver Nguyen  github

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterFunc

func FilterFunc[S ~[]E, E any](s S, fn func(E) bool) (outs []E)

FilterFunc returns a new slice with elements that satisfy the function.

func FilterMapFunc added in v0.1.0

func FilterMapFunc[S ~[]E, E any](s S, fn func(E) (E, bool)) (outs []E)

FilterMapFunc (or FilterMapFunc) returns a new slice with elements that satisfy the function, and maps them to a new type.

func First

func First[S ~[]E, E any](s S) (out E)

First returns the first element of the slice.

func FirstFunc

func FirstFunc[S ~[]E, E any](s S, fn func(E) bool) (out E)

FirstFunc returns the first element of the slice that satisfies the function.

func FirstN added in v0.1.0

func FirstN[S ~[]E, E any](s S, n int) (out []E)

FirstN returns the first n elements of the slice.

func Get added in v0.1.0

func Get[S ~[]E, E any](s S, n int) (out E)

Get returns the element at index n. If n is negative, it returns from the end.

func GetOr added in v0.1.0

func GetOr[S ~[]E, E any](s S, n int, fallback E) (out E)

GetOr returns the element at index n. If n is negative, it returns from the end. If n is out of range, it returns the fallback value.

func GetOrFunc added in v0.1.0

func GetOrFunc[S ~[]E, E any](s S, n int, fallback func() E) (out E)

GetOrFunc returns the element at index n. If n is negative, it returns from the end. If n is out of range, it returns the result of the fallback function.

func GetX added in v0.1.0

func GetX[S ~[]E, E any](s S, n int) (out E, ok bool)

GetX returns the element at index n. If n is negative, it returns from the end.

func Last

func Last[S ~[]E, E any](s S) (out E)

Last returns the last element of the slice.

func LastFunc

func LastFunc[S ~[]E, E any](s S, fn func(E) bool) (out E)

LastFunc returns the last element of the slice that satisfies the function.

func LastN added in v0.1.0

func LastN[S ~[]E, E any](s S, n int) (out []E)

LastN returns the last n elements of the slice.

func MapFilterFunc

func MapFilterFunc[S ~[]E, E, R any](s S, fn func(E) (R, bool)) (outs []R)

MapFilterFunc (or FilterMapFunc) returns a new slice with elements that satisfy the function, and maps them to a new type.

func MapFunc

func MapFunc[S ~[]E, E, R any](s S, fn func(E) R) []R

MapFunc returns a new slice with elements mapped to a new type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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