Error: Nil when slicing beyond list bounds in gleam/list.slice
0 reputation · 20 Nov 2020, 02:15 UTC
Goal
Determine whether the Gleam standard library should introduce a dedicated paginated list type to enable efficient traversal of large datasets without repeated O(n) slicing costs.
Constraints and uncertainty
Using gleam/list.slice for pagination incurs linear time per page due to two traversals (drop then take), which becomes expensive for deep pages in linked lists. The gleam/iterator module offers lazy sequences that avoid repeated work but requires careful resource cleanup when paginating over I/O‑bound sources. It is unclear whether the language should provide a higher‑level abstraction that combines the safety of lists with the efficiency of iterators.
Should the standard library expose a paginated list type? What operations (e.g., next page, page size, total count) should it provide? How would it interoperate with existing list and iterator functions?