Operator之数学运算符(Mathematic operations)

数学运算符整理的理解难度很小,直接上代码

max/tryMax

_ = [1, 2, 3, 4]
    .publisher
    .max()
    .sink(receiveCompletion: { completion in
        ...
    }, receiveValue: { someValue in
        print("someValue: \(someValue)")
    })

同样支持自定义规则

.max { (struct1, struct2) -> Bool in
    return struct1.property1 < struct2.property1
}

min/tryMin

.min { (struct1, struct2) -> Bool in
    return struct1.property1 < struct2.property1
}

 

count

count等待上游publisher发送.finished`事件后,返回数据的个数

.count()

Made with in Shangrao,China By 老雷

Copyright © devler.cn 1987 - Present

赣ICP备19009883号-1