When we extract an object from another object and throw it into an array list, do you suggest to use double map function or one map + add to empty array list for that?
The map function is available on collections and sequences. Using the map function to add it to a new list is not a great idea since it will break the chain. I’m not quite sure I’m following your use case, if it’s not working from a collection or sequence though I wouldn’t use map at all (it also likely isn’t available as an option).
@@CodyEngelCodes I figured out several ways to do it. At last I decided on something like this. If you have a better idea, I would hear : val arrayOfData2 = response.data1.children.map { it.data2 }.toList() listAdapter.updateList(arrayOfData2)
I’ve a silly doubt , the first map function added to books gives us a book object , which returns authors . Adding map to that should give us an author object instead of list of authors
The collections operators return collections, if we did map followed by first it would give us a single author back. Alternatively if this was done on a sequence instead of a list then it would return one author at a time but you’d still collect that into a list at the end (most likely).
Great vid thanks.
Great video, subbed! :)
Thanks for the sub!
Awesome
Thanks ☺️
Thanks
Yeah, you're welcome ☺️
Almost like table joins in SQL...but with Kotlin code lol.
Neat and 'modern' way to express things
Very cool and efficient code, but I think I will stick with good old For Next loop for now just to avoid confusion.
What sort of confusion are you trying to avoid?
When we extract an object from another object and throw it into an array list, do you suggest to use double map function or one map + add to empty array list for that?
The map function is available on collections and sequences. Using the map function to add it to a new list is not a great idea since it will break the chain. I’m not quite sure I’m following your use case, if it’s not working from a collection or sequence though I wouldn’t use map at all (it also likely isn’t available as an option).
@@CodyEngelCodes I figured out several ways to do it. At last I decided on something like this. If you have a better idea, I would hear :
val arrayOfData2 = response.data1.children.map {
it.data2
}.toList()
listAdapter.updateList(arrayOfData2)
I’ve a silly doubt , the first map function added to books gives us a book object , which returns authors . Adding map to that should give us an author object instead of list of authors
The collections operators return collections, if we did map followed by first it would give us a single author back. Alternatively if this was done on a sequence instead of a list then it would return one author at a time but you’d still collect that into a list at the end (most likely).
Hi Cody. I love this video but the example is too complex. Remember people watching are either newbie or have no idea on how to use map
Hi, maybe the example is a little complex to understand for someone that doesn't know what map is.
Yes, i concur.
waste of time
Oh?