调整迭代器示例集合推迭代器的逻辑实现细节
This commit is contained in:
parent
d556abe081
commit
b8c002e39c
@ -41,19 +41,15 @@ func (s *Set[T]) Len() int {
|
||||
}
|
||||
|
||||
func (s *Set[T]) All() iter.Seq[T] {
|
||||
return func(yield func(T) bool) {
|
||||
// 迭代有序切片
|
||||
for _, v := range s.ordered {
|
||||
if !yield(v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return s.FilterMap(func(t T) bool {
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// FilterMap 筛选迭代
|
||||
func (s *Set[T]) FilterMap(fn func(T) bool) iter.Seq[T] {
|
||||
return func(yield func(T) bool) {
|
||||
// 迭代有序切片
|
||||
for _, v := range s.ordered {
|
||||
if !fn(v) {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user