Extracting Data from Maps - More Data-Oriented Programming in Kotlin

Опубликовано: 24 Ноябрь 2023
на канале: Pairing with Duncan
1,018
36

In last week’s episode (   • Data-Oriented Programming with Gradua...  ) we looked at data-oriented programming - essentially the art of using maps and lists. We wrote a couple of utility functions to extract data from maps, and used those to gradually migrate from maps to strongly typed classes.

We stopped two levels deep though, so today we will learn how to extract data from arbitrary paths. On the way we will learn to manage variable argument lists with the fold operation, a nice trick to avoid ending up with an empty argument list, and see how to easy it is to build data using maps and lists.

In this episode

00:00:45 Recap - typealias PropertySet = Map String, Any?
00:02:08 Add some tests for our existing prototyped implementation
00:02:24 We can build structured data by just nesting mapOf calls
00:03:04 Change our implementation of required to use getValue rather than get
00:06:00 Test casting failure
00:07:50 Test lists
00:08:36 We can end up with lists of the wrong type
00:09:48 Test two keys
00:11:49 Add a test for a path of three keys
00:12:51 Create a varargs extractor
00:13:21 Implement varargs with a list extractor
00:13:45 Work out the logic for list of keys
00:14:44 Ah, we can't call inline functions recursively
00:15:26 Implement with a fold instead
00:17:24 Remove special cases to increase confidence
00:17:55 Remove our two key function to test the varargs version
00:18:29 Add a test for empty varargs
00:19:09 Remove ability to have no varargs by changing the function signature
00:20:13 Check our client code is still working
00:20:33 Checkin
00:20:45 Summary and future plans

You can see a playlist of Data Oriented Programming    • Data Oriented Programming  

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.


Смотрите видео Extracting Data from Maps - More Data-Oriented Programming in Kotlin онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 24 Ноябрь 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,018 раз и оно понравилось 36 людям.