A kotlin multiplatform, reactive map-like abstract data type for fetching keyed data
Feb 27 2022 · 2 min read
Tiling is a kotlin multiplatform experiment for loading chunks of structured data from reactive sources.
Tiling is achieved with a Tiler; a pure function with an API most similar to a reactive
- The keys are queries for data
- The values are dynamic sets of data returned over time as the result of the query key.
The output of a Tiler is either a snapshot of the
Map<Key, Value> or a flattened
Tiler either a:
(Flow<Tile.Input.List<Query, Item>>) -> Flow<List<Item>>
(Flow<Tile.Input.Map<Query, Item>>) -> Flow<Map<Query, Item>>
Getting your data
Tilers are implemented as plain functions. Given a
Input, you can either choose to get your data as:
In the simplest case given a
MutableStateFlow<Tile.Request<Int, List<Int>> one can write:
The above will return a full list of every item requested sorted in ascending order of the pages.
Note that in the above, the list will grow indefinitely as more tiles are requested unless queries are evicted.
This may be fine for small lists, but as the list size grows, some items may need to be evicted and
only a small subset of items need to be presented to the UI. This sort of behavior can be achieved using
Request, and the
Order covered on the project github page: