Poké-Fun with Kotlin and Arrow
Welcome! In this guide we (well, actually you) are going to work on an application to build decks for the Pokémon Trading Card Game (TCG). Each chapter roughly corresponds to a different functionality: loading decks, searching cards, and so on. Following the spirit of these times, we also hint at using (local) AI in the application.
The source code is available in this repository. Fork and clone your own fork with submodules, either by using IntelliJ IDEA or with
git clone --recurse-submodules <your-fork-url>.
This book assumes that you know your way around Kotlin, but previous experience with functional programming or Arrow, or with Compose Multiplatform, is not required.
Many of these sections complement the book Functional Programming Ideas for the Curious Kotliner.
The starting point introduces the domain and the main components of the technology.
- If you have never heard of the Pokémon Trading Card Game or don't know the rules, start with the introduction to the domain;
- If you are new to the Kotlin Toolchain or Compose Multiplatform, start with the technology,
- If you are new to local LLMs for AI, follow the local LLM setup instructions.
Afterward, the overview describes the main components of the given code. The rest of the guide is divided into a series of largely independent sections, so you can choose what you want to work on. Each section contains an introduction to one or more topics, and pointers to additional tutorials or documentation about them.
- What is (in) a deck: model data using data classes and sealed hierarchies.
- Law-abiding decks: check that the deck follows the rules, and learn about
Raisealong the way. - Deck building: design a good
ViewModelusing functional principles, and design undo/redo with actions-as-data. - Deal with bad internet: improve the experience with
ScheduleandCircuitBreaker, and cache results using memoization. - Through the magnifying glass: use optics to improve the code, and use local storage for card data.
- Loading and saving: store your work locally, and learn about parallel combinators in Arrow Fx.
- Better architecture: introduce resource management, and overall nicer design.
- Nicer UI: implement more visual feedback using Compose Multiplatform.
- Fancy deck titles: learn the basics of AI agents to generate titles for the deck.
- More ideas for AI: use more AI functionality to spice the application.
To guide you through the material, sections and tasks are marked with different Pokémon:
Oddish for basic tasks about the topic at hand;
Vileplume for additional practice;
Jirachi marks sections that involve thinking and understanding trade-offs.
If you want to learn what functional programming is about, we recommend the
Oddish sections, and focus on
data modelling, validation, actions as data and optics.