165: Learning Kotlin: Lambda Expressions Part 1


Download

In this episode, Donn talks about Kotlin Lambda Expressions. He explains the syntax and how to build a couple of simple lambda expressions with and without type inference and declaration. We wrap up with a small example of passing a small lambda with multiple values to a function. See the show notes below for more info. This is part 1 of a multi-part series on Lambda Expressions in Kotlin.

The basic syntax of a lambda expression: kotlin
val myLambda : Type = { argumentList -> codeBody }

The codeBody is the only section that is not optional.

Double lambda expression (doubles an integer) with type inference kotlin
val double = { number: Int -> number * 2 }
val result = double(4)
// result = 8 now

Double string multi-line lambda with type inference. kotlin
val doubleString = { number: Int ->
// codebody
val doubleResult = number * 2
doubleResult.toString()
// Kotlin knows this will return a string
}

Type declaration in a lambda kotlin
val myLambda: (String, Int) -> String = { str, int ->
"$str - ${int.toString()}" // "Donn - 32"
}
val result = myLambda("Donn", 32)
// result = "Donn - 32"

Preview of next week … passing a lambda to a function `\kotlin fun doWork(name: String, favoriteNumber: Int, someLambda: (String, Int) -> String) { // Do some processing, this is a contrived example val repeatedString = “$name$name” val result = someLambda(repeatedString, favoriteNumber) println(result) }

// Usage doWork(“Donn”, 32) { str, int -> val someNewValue = “$str is my parameter and so is $int” someNewValue.length.toString() // this is returned }

// ’37’ is printed via println

// Or use it like this, the lambda code body is what can change, this is where the power is at doWork(“Donn”, 32) { name, count -> var result = “” for(i in 1..count) { result += “$name” } result // this is returned }

// loops over and concatinates “Donn” until the favorite number (aka count) is met. // Output looks like: “DonnDonnDonnDonnDonnDonn…” and so on…

`\

164: Learning Kotlin: Sealed Classes


Download

In this episode, you’ll learn all about Kotlin Sealed classes. Donn walks you through what they are, how to create them, how to use data classes, objects and regular classes to create a restricted type hierarchy.

Sponsors 🙏

Contact

157: Effective Java Item# 20 – Prefer interfaces to abstract classes


Download

In this episode, Donn talks about Item #20 in the Effective Java book (third series) by Joshua Bloch. He discusses why you should think about using interfaces over abstract classes, how they can add mixin like behavior to retrofit existing classes with new behavior, default methods, skeleton implementations and more.

Enjoy.

Sponsors 🙏

Contact

156: Increase App Engagement with Android Q


Download

With the release of Android Q we now have the settings panel and all its glory. This panel, while most likely overlooked as a minor feature, is actually a diamond in the rough.

Why?

Simply because it’s going to lower the abandonment rate of your app and increase the engagement of your app at the same time. Donn talks about this in depth in this episode.

Enjoy.

Shownotes

Sponsors 🙏

Contact

154: Developer Growth: Start Writing


Download

Growing as a developer is important for you, your career and your future. One of the best ways to grow your career is to start writing.

Donn recommends starting a blog or contributing to a blog. The process of writing will expose your weak points in your comprehension of a topic. Refining your communication skills through writing and putting thoughts out into the universe via a blog will broaden your skills as a developer.

Ultimately, writing is about communication and communication is the cornerstone of success in much of anything. In this episode, Donn walks you through why you should start writing to help you grow as a developer.

Enjoy.

Sponsors 🙏

Contact