Clean Flow Transformations with Combine, Zip & Merge - Kotlin Flows

  Рет қаралды 28,624

Philipp Lackner

Philipp Lackner

Күн бұрын

Пікірлер: 50
@김정훈-y6b1p
@김정훈-y6b1p Жыл бұрын
Thanks to this, I used combine to conveniently merge the results in the method of sequentially calling multiple suspend functions and merging the results. Thank you!
@ernestguevara5968
@ernestguevara5968 7 ай бұрын
Thanks I needed a clean and quick explanation and demo of this for a code optimization. When ever I need android stuff I'd just search your name with the topic and probably you made a video about that!!! 👍👍👍
@Alchemist10241
@Alchemist10241 Жыл бұрын
Philipps' tutorials make programming so much easier and enjoyable
@itsic-marking3159
@itsic-marking3159 2 жыл бұрын
Like this format, simple, clear, no digression
@alekseyyakovlev6924
@alekseyyakovlev6924 2 жыл бұрын
Isn't it better to use combine(flow1,flow2,flow3...) syntaxis for 3 and more flows?
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Thanks to some comments I learnt that this exists😂
@federicocreti4699
@federicocreti4699 2 жыл бұрын
This is true, I use combine(flow1, flow2, flow3). But thank to this video I reflected that maybe there are cases where the Philipp sintax is better. It maybe helps to divide some concepts of the flows
@mikeshin77
@mikeshin77 2 жыл бұрын
Your video lecture is really helpful! Thanks a lot.
@Camlon
@Camlon 2 жыл бұрын
I was struggling a little in my personal project due to having multiple flows where some need to wait for another to finish and you came with a solution I didn't know existed. Thanks for another great video, Philipp.
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Glad it helped!
@abada-s
@abada-s 2 жыл бұрын
So combine will fire when one of two flows emits a new value Zip will fire when both flows emit new values Merge will listens to all flows that we pass to it and collect every value from any of them
@haykmkrtchyan7093
@haykmkrtchyan7093 11 ай бұрын
For combine we can use also something like this val resultFlow: Flow = combine( _flowOne, _flowTwo, _flowThree, ) { flowOne, flowTwo, flowThree -> flowOne.length > 10 && flowTwo < 20 && flowThree }.stateIn( scope = viewModelScope, started = SharingStarted.Eagerly, initialValue = false, ) Merge just accepts flows with the same type, whereas combine can accept flows with different types. Zip is more similar to combine than merge, hence people tend to think that merge is more similar to combine 😁
@enikebraimoh
@enikebraimoh 2 жыл бұрын
Been waiting for this 💯💯🔥🔥
@miladhashemzadeh5626
@miladhashemzadeh5626 2 жыл бұрын
Another Gr8 gr8 gr8 toturial by phillip
@TheMikkelet
@TheMikkelet 7 ай бұрын
Practical uses for Zip is when you're waiting for several asynchrounous functions to finish (such as web requests), and you only want to continue when all of them are done
@damorpl
@damorpl 2 жыл бұрын
There is also a standalone combine function that takes multiple flows, similar to merge. Just in case someone needs that.
@jpdsah
@jpdsah 2 жыл бұрын
we can also overload the combine function so that any numbers of flows and any type of flows can be combined together
@princeneo294
@princeneo294 Жыл бұрын
@@jpdsah yeah, I actually did this in a project that I'm working on
@tmjromao
@tmjromao 2 жыл бұрын
Hello Philipp, many thanks for the clear explanation. Top! Could you do video explain your prefered way to load the data model layer from a JSON file? This is so easy, and common on iOS. Did found a how to explanation for a Jetpack Compose project. Much appreciated. Best!
@CivoMT
@CivoMT 2 жыл бұрын
Best straightforward explanation out there. Thnx a lot :-)!
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Thank you!
@amateur_gamer101
@amateur_gamer101 2 жыл бұрын
Thank you for this.
@Rashilamba-iz4ii
@Rashilamba-iz4ii Жыл бұрын
Thanks
@jeckonly5853
@jeckonly5853 2 жыл бұрын
Though i don;t have time to watch yet, I come in to click the like button first🥰
@CitizenWarwick
@CitizenWarwick 2 жыл бұрын
Hey Philip thanks for that, I was hoping you might show how to combine flows and use the result of the first flow as arguments to the combined flow. I had a situation where I wanted to do this and could not figure it out :( any ideas?
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Isn't this what I showed?
@CitizenWarwick
@CitizenWarwick 2 жыл бұрын
@@PhilippLackner maybe I'm not explaining correctly or missed something Imagine you have a flow but you want to combine a second flow however you need the result of the first flow to use as arguments to a function that returns the second flow you wish to combine, hope that makes sense!
@illyaevseev312
@illyaevseev312 2 жыл бұрын
@@CitizenWarwick val argumentFlow = (1..100).asFlow() val flowResult = argumentFlow.mapLatest { " -> $it" } combine(argumentFlow, flowResult) { arg, res -> "$arg$res" }
@MrDefiler82
@MrDefiler82 Ай бұрын
in the example with combining three states can I use filter ? for example isAuthenticated.filter { it == true }.combine(user) { user -> user }.combine(posts) { user, posts -> .... }
@alekseirozhnov3038
@alekseirozhnov3038 2 жыл бұрын
Hi Philipp! Love your videos. I found one issue with the approach you covered in this video and I am unclear about possible solutions. Maybe you could shed some light on it. The issue is that when you launch the combine in viewModelScope it combines the flows asynchronously, however, there are many cases where you'd want to get a synchronous result of combining multiple flows. Here is a simple example: * 5 text fields where user enters a number * each of those fields has a mutable state containing a number entered * there's a text field where you want to display a sum of all numbers entered. When using combine().launchIn() approach the resulting sum will be displayed with an unnecessary delay caused by a launched coroutine. In this case, it would make sense to combine states synchronously. i.e once the state of an individual field is updated, the resulting state must be updated immediately. A more relevant example might be having a draggable element on a screen. If you wanna use the dragging position to combine with other states. You could observe dragging state and resulting combined state separately in your view to avoid dragging delay. However it would be so much nicer to just observe 1 stateflow from ViewModel which would be the combined state. Please let me know if you have an answer in your mind :)
@ilyastoletov
@ilyastoletov Жыл бұрын
try cachedIn() instead of launchIn()
@mustafaammar551
@mustafaammar551 2 жыл бұрын
very cool video thank you BRO👍👍👍
@pumaelgatosiberian5047
@pumaelgatosiberian5047 2 жыл бұрын
offtop but I cant find answer, Philipp, tell me please, if my screen contains bluetoothadapter, bluetooth callback etc where should I store it? If no fragments, just Activity with navhost. May be you will do some video with such a content, google don't know about how to do it, thanks in advance!
@Shriharshpathak
@Shriharshpathak 5 ай бұрын
So, technically, even though we are able to combine more than 2 flows, they won't run concurrently. RxJava's zip can combine upto 4 concurrent API calls...
@ChrisCologne84
@ChrisCologne84 2 жыл бұрын
Philipp do you use ExperimentalApi's in production?
@gulfappdeveloper2849
@gulfappdeveloper2849 2 жыл бұрын
very useful video
@AzadKumar-zi5lm
@AzadKumar-zi5lm 2 жыл бұрын
sir, can you make video on full guide to flow start to end point ✅
@Rafael-hk9pg
@Rafael-hk9pg 2 жыл бұрын
Great video, thanks a lot. How can I get a SavedStateHandle object into a MutableStateFlow?
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Use the latest lifecycle dependency, then you can call getStateFlow in the saved state handle
@federicocreti4699
@federicocreti4699 2 жыл бұрын
What is different of use flow.combine(flow2).launchIn(........ Or combine( flow1, flow2, flow3 )..... ?
@pumaelgatosiberian5047
@pumaelgatosiberian5047 2 жыл бұрын
very helpfull!
@sikka09
@sikka09 2 жыл бұрын
Hello sir, can you create a video about implement text prediction for custom keyboard app.i search every where in the internate but i cant find any good tutorial.
@joko_pryn
@joko_pryn 2 жыл бұрын
Reactive programming ❤️
@vigneshkarthi3321
@vigneshkarthi3321 2 жыл бұрын
Bro how to build video player that need to support all video format.
@RafaelRunaway
@RafaelRunaway Жыл бұрын
how about reduce function?
@udhdbdjxisskka
@udhdbdjxisskka 7 ай бұрын
So what's the difference between combine and merge? Doesn't seem to be any?
@jopadjr
@jopadjr 2 жыл бұрын
387th...Thanks Philipp
@sh3r1p49
@sh3r1p49 2 жыл бұрын
@kirwakelvinkering3122
@kirwakelvinkering3122 Жыл бұрын
I think the concept of what flows mean should not be taken so lightly ,i find it challneging.Thanma Philip for this ,however ,we request you yo make another tutorial on the same where you will demistofy it once and for all .Kind regards.
@nirmalmudaliar4284
@nirmalmudaliar4284 2 жыл бұрын
First
Сюрприз для Златы на день рождения
00:10
Victoria Portfolio
Рет қаралды 2,4 МЛН
How it feels when u walk through first class
00:52
Adam W
Рет қаралды 24 МЛН
#7 Kotlin Coroutines Flow. StateFlow. SharedFlow || Курс по корутинам
20:41
Android Broadcast. Все об Андроид разработке
Рет қаралды 29 М.
Модули в Android Clean Architecture на практике
20:57
Тимофей Коваленко
Рет қаралды 26 М.
StateFlow & SharedFlow - The Ultimate Guide to Kotlin Flows (Part 3)
23:11
Миграция с LiveData на Coroutines Flow
25:02
Android Broadcast. Все об Андроид разработке
Рет қаралды 29 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 88 М.
Kotlin Flow Operators: Merge, Zip, Combine
10:01
Charfaoui Younes
Рет қаралды 919
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 80 М.
Kotlin Flows in practice
21:06
Android Developers
Рет қаралды 163 М.