refactor(csync): remove NewMapFromSeq in favor of maps.Collect

林玮 (Jade Lin) created

Change summary

internal/csync/maps.go      | 10 ----------
internal/csync/maps_test.go | 25 -------------------------
internal/llm/agent/agent.go |  3 ++-
3 files changed, 2 insertions(+), 36 deletions(-)

Detailed changes

internal/csync/maps.go 🔗

@@ -27,16 +27,6 @@ func NewMapFrom[K comparable, V any](m map[K]V) *Map[K, V] {
 	}
 }
 
-// NewMapFromSeq creates a new thread-safe map from an iter.Seq2 of key-value pairs.
-func NewMapFromSeq[k comparable, v any](seq iter.Seq2[k, v]) *Map[k, v] {
-	m := make(map[k]v)
-	seq(func(kk k, vv v) bool {
-		m[kk] = vv
-		return true
-	})
-	return NewMapFrom(m)
-}
-
 // NewLazyMap creates a new lazy-loaded map. The provided load function is
 // executed in a separate goroutine to populate the map.
 func NewLazyMap[K comparable, V any](load func() map[K]V) *Map[K, V] {

internal/csync/maps_test.go 🔗

@@ -37,31 +37,6 @@ func TestNewMapFrom(t *testing.T) {
 	require.Equal(t, 1, value)
 }
 
-func TestNewMapFromSeq(t *testing.T) {
-	t.Parallel()
-
-	original := map[string]int{
-		"key1": 1,
-		"key2": 2,
-	}
-	seq := func(f func(string, int) bool) {
-		for k, v := range original {
-			if !f(k, v) {
-				break
-			}
-		}
-	}
-
-	m := NewMapFromSeq(seq)
-	require.NotNil(t, m)
-	require.Equal(t, original, m.inner)
-	require.Equal(t, 2, m.Len())
-
-	value, ok := m.Get("key2")
-	require.True(t, ok)
-	require.Equal(t, 2, value)
-}
-
 func TestNewLazyMap(t *testing.T) {
 	t.Parallel()
 

internal/llm/agent/agent.go 🔗

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"log/slog"
+	"maps"
 	"slices"
 	"strings"
 	"time"
@@ -1072,7 +1073,7 @@ func (a *agent) setupEvents() {
 				tools := getTools(ctx, name, c)
 				updateMcpTools(name, tools)
 				// Update the lazy map with the new tools
-				a.mcpTools = csync.NewMapFromSeq(mcpTools.Seq2())
+				a.mcpTools = csync.NewMapFrom(maps.Collect(mcpTools.Seq2()))
 				updateMCPState(name, MCPStateConnected, nil, c, a.mcpTools.Len())
 			default:
 				continue