Collection Operations
The extension-function toolbox over Iterable: transforming, aggregating, grouping, windowing, ordering, and searching. Interviewers often just hand you a data-shaping task and watch which operators you reach for.
part ofKotlinoverview, primer and where to startread it →on this pageshowhide
explore
- Transformations6 questions
- Aggregation & Folding5 questions
- Grouping & Association5 questions
- Windowing, Chunking & Zipping6 questions
- Ordering & Comparators5 questions
- Element Access & Search5 questions
questions
page 2 of 2Combine zip, unzip, windowed, and flatten to build a small pipeline: given two parallel lists of timestamps and temperatures, compute per-interval rate-of-change. Walk through your operator choices.
basics
~20 sPair the two lists with zip so each reading is one (time, temp). Slide a 2-wide window over the readings to get consecutive pairs, then for each pair divide the temperature change by the time change to get the rate. unzip can split paired data back out when needed.
When writing a custom Comparator for sortedWith, what correctness contract must it satisfy, and what goes wrong if it doesn't? How do compareBy/thenBy help you stay correct?
basics
~20 sA comparator must be consistent: if a comes before b and b before c, then a must come before c, and reversing the arguments must reverse the sign. If it isn't, sorting can give wrong or unstable results, or even throw. Using compareBy/thenBy avoids hand-written mistakes.
showing 31–32 of 32