Skip to content

Commit

Permalink
Iters
Browse files Browse the repository at this point in the history
  • Loading branch information
esafonov committed Sep 24, 2024
1 parent b1c556e commit d6823c9
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 1 deletion.
10 changes: 10 additions & 0 deletions collections/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package set
import (
"encoding/json"
"fmt"
"iter"
"strings"
)

Expand All @@ -25,6 +26,15 @@ func Of[M comparable](members ...M) Set[M] {
return result
}

// OfSeq creates a new Set from sequence.
func OfSeq[M comparable](seq iter.Seq[M]) Set[M] {
result := make(Set[M])
for member := range seq {
result[member] = struct{}{}
}
return result
}

// OfMapKeys creates a new Set of keys of the given map.
func OfMapKeys[M comparable, V any](m map[M]V) Set[M] {
result := make(Set[M])
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/gotidy/lib

go 1.20
go 1.23
Loading

0 comments on commit d6823c9

Please sign in to comment.