Swift Combine: min() & max() operator

KD Knowledge Diet
1 min readJan 29, 2023

In this article, I’m going to cover sequence operators. The sequence operators are very easy to understand because the publisher itself is the sequence itself. So sequence operator works usually on the collection like an array or a set and they are finite sequences. You must know that sequence operators like min() and max() works only on the collection with a limited amount.

min()

let publisher = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].publisherpublisher 
.min()
.sink {
print($0) //1
}

When you use min() operator, you can probably guess what’s going to happen. What you receive is the minimum value from the collection.

max()

let publisher = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].publisherpublisher 
.max()
.sink {
print($0) //10
}

When using max() operator, you are right. You will get the maximum value from the array.

Conclusion

  • Sequence operator only works with finite collections.
  • min() sinks the minimum value from the collection.
  • max() sinks the maximum value from the collection.

--

--

KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!