From 267d40bbea6036f913c4047a6a2055b3e5d7bb96 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Mon, 2 Nov 2020 10:59:16 +0100 Subject: Add Map function (#40) `Map` makes it easier to build lists of elements without having to iterate.--- gomponents_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gomponents_test.go') diff --git a/gomponents_test.go b/gomponents_test.go index 3028723..0c5dc68 100644 --- a/gomponents_test.go +++ b/gomponents_test.go @@ -183,3 +183,16 @@ func TestGroup(t *testing.T) { } }) } + +func TestMap(t *testing.T) { + t.Run("maps slices to nodes", func(t *testing.T) { + items := []string{"hat", "partyhat", "turtlehat"} + lis := g.Map(len(items), func(i int) g.Node { + return g.El("li", g.Text(items[i])) + }) + + list := g.El("ul", lis...) + + assert.Equal(t, `