Map Explained - Kotlin Collections
Вставка
- Опубліковано 25 лип 2024
- In this video we talk about the map function that is part of the Kotlin collections library. Using map allows you to transform a collection from one type to another.
As with every single video I do about software engineering, if you have any questions or comments please let me know below 😊
🚶♂️ FOLLOW ME 🚶♂️
Twitter - / codyengeltweets
Medium - / codyengel
📚 RESOURCES 📚
Learn Kotlin Repository - github.com/CodyEngel/learn-ko...
Collections Package - github.com/CodyEngel/learn-ko...
Learn more about Kotlin - kotlinlang.org/
🎥 CAMERA GEAR 🎥
Camera - amzn.to/2LM9Zt3
Microphone - amzn.to/2LLv0Eb
Lens - amzn.to/317tGPT
Main Lights - amzn.to/2K2yHDH
Back Lights - amzn.to/2Yw4HUI
External Monitor - amzn.to/2YoM2Kl
* Note: the above links are affiliate links.
🖥 DESK GEAR 🖥
Monitor - amzn.to/2yjZPqR
Headphones - amzn.to/2YBuo68
Google Nest Hub - amzn.to/30Zuki7
MacBook Pro 2019 - amzn.to/30YyuXy
* Note: the above links are affiliate links.
Great vid thanks.
Great video, subbed! :)
Thanks for the sub!
Almost like table joins in SQL...but with Kotlin code lol.
Neat and 'modern' way to express things
Awesome
Thanks ☺️
Thanks
Yeah, you're welcome ☺️
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, maybe the example is a little complex to understand for someone that doesn't know what map is.
Yes, i concur.
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
waste of time
Oh?