From d430b8c9edddd607dfdf47b5d64ac87e0365c04f Mon Sep 17 00:00:00 2001 From: fiatjaf <fiatjaf@gmail.com> Date: Mon, 10 Mar 2025 02:58:31 -0300 Subject: [PATCH] I had forgotten to implement Tags.FindAll() --- tag_test.go | 3 ++- tags.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tag_test.go b/tag_test.go index 2f91cbd..879ec24 100644 --- a/tag_test.go +++ b/tag_test.go @@ -1,6 +1,7 @@ package nostr import ( + "slices" "testing" "github.com/stretchr/testify/assert" @@ -18,7 +19,7 @@ func TestTagHelpers(t *testing.T) { assert.Nil(t, tags.Find("x"), "Find shouldn't have returned a tag with a single item") assert.NotNil(t, tags.FindWithValue("p", "abcdef"), "failed to get with existing prefix") assert.Equal(t, "ffffff", tags.FindLast("e")[1], "failed to get last") - assert.Equal(t, 2, len(tags.GetAll([]string{"e", ""})), "failed to get all") + assert.Equal(t, 2, len(slices.Collect(tags.FindAll("e"))), "failed to get all") c := make(Tags, 0, 2) for _, tag := range tags.All([]string{"e", ""}) { c = append(c, tag) diff --git a/tags.go b/tags.go index 0ca0fa5..ac15949 100644 --- a/tags.go +++ b/tags.go @@ -156,6 +156,19 @@ func (tags Tags) Find(key string) Tag { return nil } +// FindAll yields all the tags the given key/tagName that also have one value (i.e. at least 2 items) +func (tags Tags) FindAll(key string) iter.Seq[Tag] { + return func(yield func(Tag) bool) { + for _, v := range tags { + if len(v) >= 2 && v[0] == key { + if !yield(v) { + return + } + } + } + } +} + // FindWithValue is like Find, but also checks if the value (the second item) matches func (tags Tags) FindWithValue(key, value string) Tag { for _, v := range tags {