MCPcopy Create free account
hub / github.com/davecheney/pub / Map

Function Map

internal/algorithms/algorithms.go:5–11  ·  view source on GitHub ↗

Map applies the function f to each element of the slice and returns a new slice containing the results.

(s []T, f func(T) R)

Source from the content-addressed store, hash-verified

3
4// Map applies the function f to each element of the slice and returns a new slice containing the results.
5func Map[T, R any](s []T, f func(T) R) []R {
6 r := make([]R, 0, len(s))
7 for _, v := range s {
8 r = append(r, f(v))
9 }
10 return r
11}
12
13// Filter returns a new slice containing all elements of the slice that satisfy the predicate function.
14func Filter[T any](s []T, f func(T) bool) []T {

Callers 15

outboxShowFunction · 0.92
FollowersFunction · 0.92
FollowingFunction · 0.92
AttachmentsMethod · 0.92
StatusesFavouritesShowFunction · 0.92
StatusesReblogsShowFunction · 0.92
StatusesContextsShowFunction · 0.92
FavouritesIndexFunction · 0.92
BlocksIndexFunction · 0.92
TimelinesHomeFunction · 0.92
TimelinesPublicFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestMapFunction · 0.68