0 Star 0 Fork 0

蒋佳李/vault

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
filter.go 946 Bytes
一键复制 编辑 原始数据 按行查看 历史
蒋佳李 提交于 2021-03-29 17:25 . 更新
package memdb
// FilterFunc is a function that takes the results of an iterator and returns
// whether the result should be filtered out.
type FilterFunc func(interface{}) bool
// FilterIterator is used to wrap a ResultIterator and apply a filter over it.
type FilterIterator struct {
// filter is the filter function applied over the base iterator.
filter FilterFunc
// iter is the iterator that is being wrapped.
iter ResultIterator
}
func NewFilterIterator(wrap ResultIterator, filter FilterFunc) *FilterIterator {
return &FilterIterator{
filter: filter,
iter: wrap,
}
}
// WatchCh returns the watch channel of the wrapped iterator.
func (f *FilterIterator) WatchCh() <-chan struct{} { return f.iter.WatchCh() }
// Next returns the next non-filtered result from the wrapped iterator
func (f *FilterIterator) Next() interface{} {
for {
if value := f.iter.Next(); value == nil || !f.filter(value) {
return value
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jiangjiali/vault.git
git@gitee.com:jiangjiali/vault.git
jiangjiali
vault
vault
v1.1.9

搜索帮助