Combine操作符Mathematic示例
5个月前 • 173次点击 • 来自 移动端
标签: Swift
Mathematic 数学
Mathemati常用于求数据集合中的最大值,最小值或者个数
max/tryMax
[1, 2, 3, 4]
.publisher
.max()
.sink(receiveValue: { someValue in
print("someValue: \(someValue)")
})
自定义类可通过实现Comparable
协议或者直接在max
闭包中指定实现规则
.max { v1, v2 -> Bool in
v1.property < v2.property
}
min/tryMin
同max/tryMax,略
count
上游publisher发送.finished事件后,返回数据的个数
[1, 2, 3, 4]
.publisher
.count()
.sink(receiveValue: { someValue in
print("someValue: \(someValue)")
})