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)
| 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. |
| 133 | func 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 |
no outgoing calls
no test coverage detected