【发布时间】:2021-11-29 15:28:04
【问题描述】:
过滤一个 Observable 列表后,我可能有一个空列表。我只对包含填充列表的事件感兴趣。有什么办法可以阻止空事件传播到onNext?
let source: BehaviorRelay<[Int]> = .init(value: [])
source
.map { nums -> [Int] in
return nums.filter { $0 < 10 }
}
/// What can go here to stop/block/ignore an empty list
.subscribe(onNext: { nums in
print("OKPDX \(nums)")
})
source.accept([1, 9, 13])
// prints "[1, 9]" (all good)
source.accept([20, 22, 101])
// prints "[]" (not desirable, I'd rather not know)
【问题讨论】: