Add MapIter to map over iterators
1 file changed, 18 insertions(+), 0 deletions(-)
changed files
M gomponents_test.go → gomponents_test.go
@@ -5,6 +5,7 @@ "errors" "fmt" "io" "os" + "slices" "strings" "testing"@@ -300,6 +301,23 @@ return g.El("li", g.Textf("%v: %v", key, value)) })) _ = e.Render(os.Stdout) // Output: <ul><li>party: hat</li><li>super: hat</li></ul> +} + +func TestMapIter(t *testing.T) { + items := slices.Values([]string{"party hat", "super hat"}) + e := g.El("ul", g.MapIter(items, func(value string) g.Node { + return g.El("li", g.Text(value)) + })) + assert.Equal(t, `<ul><li>party hat</li><li>super hat</li></ul>`, e) +} + +func ExampleMapIter() { + items := slices.Values([]string{"party hat", "super hat"}) + e := g.El("ul", g.MapIter(items, func(value string) g.Node { + return g.El("li", g.Text(value)) + })) + _ = e.Render(os.Stdout) + // Output: <ul><li>party hat</li><li>super hat</li></ul> } func TestGroup(t *testing.T) {