Join Scott Gardner for an in-depth discussion in this video Filter observable sequences, part of Reactive Programming in iOS with RxSwift.
- [Voiceover] In addition to transforming…observable sequences, you'll frequently want…to filer observable sequences to only react…to next events based on certain criteria.…For example, let's say we have a sequence of integers…and we want to work only with prime integers,…that is greater than one and only divisible…by itself and one.…We can use the filter operator here.…Filter applies a predicate to each element…emitted and only allows those elements through that pass.…To set this up, I'll use the generate operator,…which can be used generate an observable sequence.…
In this case, I'll create a sequence of integers…from one to 100.…To show the result, I'll print it out in a subscription.…I'll delete that subscription though,…because I'm going to use the filter operator…with this observable sequence.…Filter takes a predicate that will be applied…to test each element, in this case an integer,…and it will return a Bool.…First, I'll guard that the number is greater than one,…or else return false.…
Then, I'll create a local variable to hold…
Learn reactive programming with Reactive Extensions for Swift and iOS by following along with author Scott Gardner. Scott introduces the Reactive Extensions libraries for Swift and Cocoa Touch, and shows how to work with observable sequences, bind user interface and data elements, perform networking operations, debug Rx code, and more.
- Using the Reactive Extensions library
- Working with observable sequences
- Binding UI and data elements
- Binding table and collection views
- Error handling