android_catalogue1-8 Exercise 3: flatMapLatest and Escaping ============================================================ 1. map instead of flatMapLatest. map would produce a Flow of flows, and collecting each one separately means several database flows stay active at once. Example timings: the user types "d" then "du". Query "d" matches many rows and takes 80 ms; query "du" takes 20 ms. "du" finishes first and shows 2 items; then "d" finishes and its 40 items replace them. The screen ends up showing results for "d" while the box says "du". Worse, the old flow keeps emitting whenever the table changes, so stale results can overwrite fresh ones at any later time. flatMapLatest CANCELS the previous flow the moment new filters arrive, so only the newest query can ever deliver results. 2. No escaping of % in "100%". The pattern would be %100%% : the trailing % characters are wildcards, so it simply means "contains 100". The user would see "100% Pure" but also "Top 100 Albums" and "1000 Miles", and the "You already have N matching items" heading would over-count. Likewise "a_b" would match "aXb". With the escape, %100\%% means "contains the exact text 100%". Both bugs are silent: nothing crashes, the results are just wrong, so they need a deliberate test.