Intro to Collection Builders in Kotlin

  Рет қаралды 3,662

Dave Leeds

Dave Leeds

Жыл бұрын

Use Kotlin's Collection Builders to dynamically build out a collection's contents, without leaving it open to modifications. In this video, I'll show you what they are, and why you'd want to use them. And as a bonus, we'll even take a look at immutable collections!
New to Kotlin? Start learning here:
typealias.com/start/

Пікірлер: 40
@derekdevs
@derekdevs Жыл бұрын
I’m so glad I found your channel. Thank you for this quality content! As a new-to-Kotlin dev, I greatly appreciate it.
@typealias
@typealias Жыл бұрын
That's very kind of you to say, Derek! I'm so glad you're enjoying it!
@thatdougsmith
@thatdougsmith Жыл бұрын
These are some of the best quality development videos I've ever seen! It's amazing they're free!
@typealias
@typealias Жыл бұрын
Thank you so much, Doug! I'm having lots of fun creating them! 🙂
@somethingkindawierd
@somethingkindawierd Жыл бұрын
I love the animations on top of the code. Makes it super easy to follow the narration.
@typealias
@typealias Жыл бұрын
Thanks Jon! I know that animation in the wrong place or time can be more distracting than helpful, so I'm trying to be intentional about where I put it. I'm glad to hear that it worked well here! 🙂
@stephenmorse8207
@stephenmorse8207 Жыл бұрын
Thank you, I love your videos! I wish the immutable library was part of the standard library 😁
@typealias
@typealias Жыл бұрын
Yeah, I also wish they were in stdlib. While poking around with things, I did see that the Kotlin compiler itself does make use of the immutable collections library. Sounds like the Kotlin team has lots of big things planned for after the K2 compiler lands, so I'm hoping we'll see this library get closer to a version 1.0 after that. Especially since the prototype code they showed about Collection Literals at the KotlinConf keynote included PersistentSet. 😁
@prospernglazi7444
@prospernglazi7444 Жыл бұрын
This awesome, do you have a course? Your teaching style is right up my ally
@coalacorey
@coalacorey Жыл бұрын
His website (in the video description) is a valuable resource and his "Start Learning Kotlin" illustrated guide is structured like a course 👍
@typealias
@typealias Жыл бұрын
Hey Prosper, thanks so much! I'm actively working on a course, but it's still very early. I'd be happy to set you up with "super-early" access if you're interested. If you're on LinkedIn or Twitter, just send me a direct message (or you can email me... dave at typealias), and I'll get you set up.
@jesprotech
@jesprotech Жыл бұрын
This is probably the best Kotlin video I’ve ever seen so far! I don’t think I’ve used collection builders explicitly to be honest and this is pretty amazing! You made the video very simple and very clear! It’s also quite relatable with your example and the way you posed problems and solutions in such a short video! Keep up the good work! 👍
@typealias
@typealias Жыл бұрын
Wow, thank you so much - I'm really glad you enjoyed it! More videos are in the works! 🙂
@abhimanyu.n14
@abhimanyu.n14 Жыл бұрын
Hi Dave, Very useful video. Thanks :). Would love to see some content related to Kotlin DSL if possible. You make all the concepts seems so easy.
@typealias
@typealias Жыл бұрын
Thanks so much, Abhimanyu! Are you looking for content about how to _use_ a particular DSL, or about how to make your own DSLs?
@abhimanyu.n14
@abhimanyu.n14 Жыл бұрын
@@typealias As an Android dev, Gradle groovy was very complicated for me to understand. Hoping to understand Kotlin DSL better as there is a shift from Groovy to Kotlin as the recommendation now from Google. From basics, to advanced levels possible.
@typealias
@typealias Жыл бұрын
Ah, gotcha - thanks! Yes, the Gradle DSL is definitely easier to use with Kotlin Gradle Script than with Groovy, but there's is still quite a learning curve. I've got some research I'll need to do for that one! I'll get add it to the topic list.
@JasonYork
@JasonYork Жыл бұрын
Great video Dave! Well done.
@typealias
@typealias Жыл бұрын
Thanks so much Jason! Glad you liked it! 🙂
@Mike-er2ih
@Mike-er2ih Жыл бұрын
Already watched all available videos. Very HQ - thanks!
@typealias
@typealias Жыл бұрын
Thanks so much Mike! I'm glad you like them!
@sarathexp6328
@sarathexp6328 Жыл бұрын
as usual quality content ❤
@typealias
@typealias Жыл бұрын
Thank you so much, Sarath!
@GB-nn2cx
@GB-nn2cx 4 ай бұрын
Nice topic. Thanks
@typealias
@typealias 4 ай бұрын
You're most welcome! I'm glad you liked it! 👍
@oharaandrew314
@oharaandrew314 Жыл бұрын
I wouldn't worry so much about the temporary list objects; the garbage collector is supposed to be very efficient at cleaning up short-lived immutable objects like those.
@typealias
@typealias Жыл бұрын
Yeah, and in most apps, performance is not as important as good structure and readability, anyway. At least in this case, I'd say we get both better performance _and_ better readability with buildList than with list concatenation. In any case, it'd be interesting to see some benchmarks on different Kotlin targets (JVM, Android, native, JS, WASM, etc.), for different sizes of lists to get a better understanding.
@oharaandrew314
@oharaandrew314 Жыл бұрын
@@typealias Yes, I won't dispute the improved readability at all!
@ulicqueldromal
@ulicqueldromal 3 ай бұрын
I used the immutable collections. I miss that compose multiplatform does not understand that they are stable
@typealias
@typealias 3 ай бұрын
Ah, thanks for pointing that out - I didn't realize there's an issue using them with Compose MP. I'll take a look when I get a chance!
@TimSchraepen
@TimSchraepen Жыл бұрын
I continuously forget these exist. 😅
@typealias
@typealias Жыл бұрын
Haha, yeah! It's one of those things that, the more I used it, the more I realized I needed it. 🙂
@DiaryAnan
@DiaryAnan 7 ай бұрын
His name is technically "dev lead of kotlin" 😂
@typealias
@typealias 7 ай бұрын
Haha, "Dave Leeds" -> "Dev Lead" 😅 I see what you did there!
@pavelpetrov5328
@pavelpetrov5328 Жыл бұрын
Make more vids :)
@typealias
@typealias Жыл бұрын
Haha, definitely will do! 😁
@avalagum7957
@avalagum7957 Жыл бұрын
IMO, contents.mapIndexedTo(result) { num, c -> "$num $c" } is more difficult to understand than contents.forEachIndexed { num, c -> result.add("$num $c") } Does mapIndexedTo have any advantage over forEachIndexed?
@typealias
@typealias Жыл бұрын
Hi Ava - As used here, there are no functional differences between those two approaches. The return types are different, though - mapIndexedTo() returns the list, whereas forEachIndexed() returns Unit. So, in situations where you might want to chain calls together, mapIndexedTo() might be a more natural fit. But since we aren't chaining calls in these examples, forEachIndexed() is a fine choice!
@avalagum7957
@avalagum7957 Жыл бұрын
@@typealias Got it. Thanks. I wonder why your IntelliJ didn't show a warning at that contents.mapIndexedTo line that the returned value is ignored. Mine sometimes does. Also notice that jdk 15 was used in this video. Was this video recorded 2.5 years ago?
@typealias
@typealias Жыл бұрын
For videos, I often set the inspection level to "Syntax", to minimize distractions. In this case, though, even with the inspection level set to "All Problems", I'm still not getting a warning. Maybe there's a particular inspection that isn't enabled here...? About the JDK - you're very observant! This was recorded more like 2.5 _weeks_ ago. I do actually have more recent JDK versions here, so I'll use those in future videos. 🙂
How to Use Kotlin's Timing API
16:27
Dave Leeds
Рет қаралды 3,1 М.
Variance... without Generics!
9:01
Dave Leeds
Рет қаралды 5 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 91 МЛН
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 36 МЛН
Every Kind of Class in Kotlin
10:44
Dave Leeds
Рет қаралды 7 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 137 М.
Gradle Intro: Basics: Tasks & Configurations
1:28:33
Sebastian Sellmair
Рет қаралды 1,3 М.
Smart Casts with Kotlin Contracts
7:35
Dave Leeds
Рет қаралды 6 М.
The Essence of Coroutines
8:10
Dave Leeds
Рет қаралды 5 М.
Inline Functions: inline, crossinline, and noinline
11:59
Dave Leeds
Рет қаралды 3,5 М.
Context Receivers Are Coming to Kotlin!
31:44
Kotlin by JetBrains
Рет қаралды 37 М.
Three Simple Rules for Subtypes
13:52
Dave Leeds
Рет қаралды 1,9 М.
Wall Clocks vs. Monotonic Clocks
5:01
Dave Leeds
Рет қаралды 1,9 М.
8 Design Patterns | Prime Reacts
22:10
ThePrimeTime
Рет қаралды 388 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 91 МЛН