MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / ForEach

Function ForEach

tsunami/vdom/vdom.go:133–140  ·  view source on GitHub ↗

ForEach applies a function to each item in a slice and returns a slice of results. The function receives the item and its index, and can return any type for flexible VDOM generation.

(items []T, fn func(T, int) any)

Source from the content-addressed store, hash-verified

131// ForEach applies a function to each item in a slice and returns a slice of results.
132// The function receives the item and its index, and can return any type for flexible VDOM generation.
133func ForEach[T any](items []T, fn func(T, int) any) []any {
134 elems := make([]any, 0, len(items))
135 for idx, item := range items {
136 fnResult := fn(item, idx)
137 elems = append(elems, fnResult)
138 }
139 return elems
140}
141
142// ToElems converts various types into VDomElem slices for use in VDOM children.
143// It handles strings, booleans, VDomElems, *VDomElem, slices, and other types

Callers 3

genTableRenderFuncFunction · 0.92
app.goFile · 0.92
app.goFile · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected