Scala lists and maps
Work with ordered lists and key-value lookups. Follow a pickup roster, change a booking, or combine stock counts from two deliveries.
Lists · build and edit
- ArrayBuffer.removeTake a cancelled item off a packing list
- Vector.appendedAdd the last student to the bus register
- Vector.filterNotClear empty stock bins from the pick list
- Vector.mapClean the names on two visitor badges
- Vector.patchInsert two pickup stops before the depot
- Vector.toArraySend the badge roster to an older printer
- Vector.updatedCorrect the second stop on a shuttle route
Lists · positions and ranges
- Seq.indexOf and lastIndexOfFind both visits to the market
- Vector.liftRead the second name on the pickup roster
- Vector.reverseIteratorRead a receipt history newest first
- Vector.sliceSelect two orders for the packing bench
Maps · look up and assign
- Map.containsFind a parcel whose driver is still unassigned
- Map.updatedUpdate the count for a shelf label
- Map.updatedWith and OptionChange a room assignment only if it is still current
Maps · combine and transform
- Immutable Map versionsKeep the price shown on yesterday's menu
- Map concatenationApply weekend opening hours
- Map.toSeq and sortByPrint shelf totals in aisle order
- Map.updatedWithReduce only the stock that is on the ledger
- mutable.Map.getOrElseUpdateGroup two parcels on one delivery route
Other collection guides
- groupMapReduceTotal item quantities by warehouse
- Iterable.partitionSeparate passing and failing records
- Map.updated and getOrElseBuild counts while preserving the original snapshot
- List.containsCheck for a price in a sale list
- List.countCount items at the offer price
- List.minFind the cheapest item in a basket
- List.sumAdd the prices on a shopping list
- Map.getOrElseShow a default when a product has no stock entry