Video summary
Kotlin Basics || Add Book Function || Humble Coders
Main summary
Key takeaways
Summary of the Subtitles (Kotlin Basics: Adding a Book Function)
The video introduces a Kotlin function meant to add a new Book to a library, as part of a Kotlin tutorial (described as running “for 5 minutes” in the subtitles).
Function Design (Inputs, Types, Return)
The function’s purpose is to add a book to a library. It takes two inputs:
library: aList<Book>(the existing collection of books)book(sometimes referred to as the “new book”): a singleBook
Immutability and return value
Because Kotlin’s List is immutable (it can’t be modified in place), the function:
- does not change the existing
librarylist - instead creates and returns a new list
The return type is emphasized as List<Book>.
Conceptually, the new library is:
newLibrary = library + newBook
return newLibrary
Mutability Behavior Explained
Even if the variable holding the library is declared mutable, the list itself is replaced. The idea is:
- call the function to get an updated list
- overwrite the variable with that new list
Conceptually:
library = dBook(library, newBook)
In effect, the “old list” is discarded/overwritten, and the result is a new list containing both:
- the original books
- the added book
Result Shown (List Growth)
The tutorial gives an example of the library size changing:
- before: 3 books
- after adding new books: 4 books
(The subtitles mention “two, four, four books” in a slightly unclear way, but the main takeaway is that the list size increases after using the function.)
The video also implies that after getting the returned list, you can store it or print it—typically by assigning the returned list to your library variable.
Learning Takeaway
Key concepts being taught include:
- Function parameters and return types
- Working with
List<Book>under immutability rules - “Updating” a collection by using list concatenation (
library + newBook) and returning a new list - Assigning the returned value afterward, then moving toward actual app development (UI and running the app on a phone)
Main Speaker / Source
- Humble Coders (referenced in the subtitles as “Humbl(e) Coders team”)
- The speaker also mentions a “humal codes team” / similar wording in the subtitle text.