xslices

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MPL-2.0 Imports: 0 Imported by: 45

Documentation

Overview

Package xslices contains a utility functions to work with slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyN

func CopyN[S ~[]V, V any](s S, n int) S

CopyN copies first n elements. If n is greater than the length of the slice, it will copy the whole slice.

func Filter

func Filter[S ~[]T, T any](slc S, fn func(T) bool) S

Filter returns a slice containing all the elements of s that satisfy fn.

func FilterInPlace

func FilterInPlace[S ~[]V, V any](slc S, fn func(V) bool) S

FilterInPlace filters the slice in place.

func FlatMap

func FlatMap[T, R any](slc []T, fn func(T) []R) []R

FlatMap applies the function fn to each element of the slice and returns a new slice with the results. It flattens the result of fn into the result slice.

func Map

func Map[T, R any](slc []T, fn func(T) R) []R

Map applies the function fn to each element of the slice and returns a new slice with the results.

func ToMap

func ToMap[T any, K comparable, V any](slc []T, fn func(T) (K, V)) map[K]V

ToMap converts a slice to a map.

func ToSet

func ToSet[T comparable](slc []T) map[T]struct{}

ToSet converts a slice to a set.

func ToSetFunc

func ToSetFunc[T any, K comparable](slc []T, fn func(T) K) map[K]struct{}

ToSetFunc converts a slice to a set using the function fn.

Types

This section is empty.

Jump to

Keyboard shortcuts

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