Previous episode: 25. Timeout and measureInterval
Next episode: 27. Scheduling Operators
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Open the starter challenge playground for this episode. You see some code waiting for you. A subject that emits integers, a function call that feeds the subject with mysterious data, in between those parts, your challenge is to group data by batches of 0.5 seconds, turn the group data into a string, and if there is a pause longer than 0.9 seconds in the feed, print the handclap emoji. Hint, create a second publisher for this step and merge it with the first publisher in your subscription. And here's another hint. If you want to convert an int to a character, you do something like the code on screen. Pause the video, try out a solution, and come back when you're ready to see my solution. (bouncy music) How'd you do? Here's my solution. Create a first publisher derived from the subject, which emits the strings. Use collect using the byTime strategy to group data in 0.5 second batches. Map each integer value to a Unicode scalar, then to a character, and then turn the whole lot into a string. Create a second publisher derived from the subject which measures the intervals between each character. If the interval is greater than 0.9 seconds, map the value to the handclap emoji, otherwise map it to an empty string. The final publisher is a merge of both strings and the handclap emoji. Filter out empty strings for better display and then print the result. Did you get that result? If so, congratulations.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.