package xslices

import "gomo.prashantv.com/xstd/xslices"

Package xslices contains functions that extend the functionality of slices.

Index

Functions

func Map

func Map[X, Y any](xs []X, fn func(X) Y) []Y

Map runs the mapping function to map a slice to a new slice.

func MapCtx

func MapCtx[X, Y any](ctx context.Context, xs []X, fn func(context.Context, X) (Y, error)) ([]Y, error)

MapCtx runs the context-aware mapping function to map a slice to a new slice. The mapping function may return an error which stops and returns the partially mapped slice. MapCtx does not explicitly check for context errors, the mapping function is expected to respect and propagate context errors.

func MapErr

func MapErr[X, Y any](xs []X, fn func(X) (Y, error)) ([]Y, error)

MapErr runs the mapping function to map a slice to a new slice. The mapping function may return an error which stops and returns the partially mapped slice.