Skip to content

Commit b596fdb

Browse files
committed
Add Collect()
1 parent 44bc27a commit b596fdb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

iter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ func IterValues[K comparable, V any](m map[K]V) iter.Seq[V] {
3333
}
3434
}
3535
}
36+
37+
// Collect returns a new map with the key-value pairs from seq.
38+
func Collect[K comparable, V any](seq iter.Seq2[K, V]) map[K]V {
39+
result := make(map[K]V)
40+
for k, v := range seq {
41+
result[k] = v
42+
}
43+
return result
44+
}

0 commit comments

Comments
 (0)