extension ObservableConvertibleType where E: Equatable {
//将原始序列(当前值)转换成(当前值, 是否与最初值相同)的序列
func isEqualOriginValue() -> Observable<(value: E, isEqualOriginValue: Bool)> {
return self.asObservable()
.scan(nil){ acum, x -> (origin: E, current: E)? in
if let acum = acum {
return (origin: acum.origin, current: x)
} else {
return (origin: x, current: x)
}
}
.map { ($0!.current, isEqualOriginValue: $0!.origin == $0!.current) }
}
}
参考文章:Swift - RxSwift的使用详解66(检测当前值与初始值是否相同:isEqualOriginValue)
网友评论