Skip to content

Commit

Permalink
feat: transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Apr 3, 2024
1 parent 40b57de commit dea6ced
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/utils/each.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package utils

import htmx "github.com/zeiss/fiber-htmx"

// Transformer is a function that transforms a node.
type Transformer[T any] func(el T) htmx.Node

// ForEach loops over the content.
func ForEach[T any](transformer Transformer[T], elems ...T) htmx.Node {
nodes := []htmx.Node{}

for _, n := range elems {
nodes = append(nodes, transformer(n))
}

return htmx.Group(nodes...)
}

0 comments on commit dea6ced

Please sign in to comment.