#collections
25 snippets tagged with #collections
Collections Module Patterns
Use Counter, defaultdict, deque, namedtuple, and ChainMap from the collections module.
Best for: counting
HashMap Operations and Patterns
Essential HashMap operations: put, get, merge, compute, getOrDefault, and iteration patterns.
Best for: Counting word frequencies in text
Java Streams — Filter, Map, Collect
Process collections with Java Streams: filter, map, flatMap, reduce, and collect to lists or maps.
Best for: Transforming and filtering collections
Concurrent Collections — Thread-Safe Maps
Use ConcurrentHashMap, CopyOnWriteArrayList, and BlockingQueue for thread-safe data structures.
Best for: Thread-safe caching in multi-threaded applications
Java Generics — Bounded Types and Wildcards
Master Java generics: bounded types, wildcards, generic methods, and type-safe collection utilities.
Best for: Type-safe generic utility methods and classes
Java List Operations and Utilities
Essential List operations: create, sort, search, transform, partition, and immutable list patterns.
Best for: Common list manipulation patterns
Comparator Chains — Multi-Field Sorting
Sort objects by multiple fields using Comparator.comparing, thenComparing, and custom comparators.
Best for: Multi-field sorting for display and reporting
Java Map — Advanced Operations
Master Map operations: compute, merge, getOrDefault, multi-map, BiMap, and stream-based grouping.
Best for: Aggregation and grouping operations on data
Custom Iterator and Iterable
Implement custom iterators and iterables for specialized data traversal and lazy sequence generation.
Best for: Lazy sequence generation for large datasets
MultiMap and BiMap Implementations
Implement MultiMap and BiMap data structures for one-to-many and bidirectional key-value mappings.
Best for: Tag/category systems with multiple values per key
Collections — map, filter, groupBy, and More
Master Kotlin collections: functional transformations, aggregations, grouping, and partition operations.
Best for: Data processing and transformation pipelines
Collection Builders — buildList, buildMap, buildSet
Build collections conditionally and dynamically with Kotlin collection builders.
Best for: Conditional list/map construction
Map Operations — Transform, Merge, Group
Advanced map operations: groupBy, associate, flatMap, merge strategies, and map transformations.
Best for: Data aggregation and grouping
List Transformation Patterns
Master list operations: windowed, chunked, zip, fold, scan, partition, and custom transforms.
Best for: Data processing pipelines
Multimap, Grouping, and Counting Patterns
Build multimaps, aggregate data, count occurrences, and perform grouped reductions in Kotlin.
Best for: Log aggregation and analysis
Collection Transformations and Aggregations
Master Kotlin collection operations: groupBy, partition, associate, zip, windowed, and aggregate.
Best for: Data aggregation and reporting
Collections Map Filter Fold Operations
Master Scala collections: map, flatMap, filter, fold, groupBy, partition, and zip operations.
Best for: Data transformation and aggregation
Map and HashMap Operations
Work with Scala Maps: create, update, merge, transform, and use default values.
Best for: Configuration management
Set Operations and Algorithms
Perform set operations: union, intersection, difference, subsets, and practical set algorithms.
Best for: Deduplication and uniqueness
Thread-Safe Concurrent Collections
Use concurrent collections for thread-safe access: TrieMap, concurrent queues, and synchronized wrappers.
Best for: Thread-safe service registries
Mutable Collections and Buffers
Use mutable collections: ArrayBuffer, ListBuffer, mutable Map/Set, and when to choose mutable vs immutable.
Best for: Performance-critical collection building
Java Interop and Collections
Work with Java libraries from Scala: collection conversions, null safety, and API wrapping.
Best for: Using Java libraries from Scala
List Operations Basics
Essential list operations: head, tail, cons, zip, groupBy, sliding, partition, and span.
Best for: Data processing and transformation
Advanced Map Operations
Advanced Map usage: merge, transform, groupMapReduce, default values, and nested maps.
Best for: Data aggregation and grouping
GroupBy, Partition, and Aggregate
Group, partition, and aggregate collections: groupBy, groupMapReduce, partition, and sliding aggregations.
Best for: Data analysis and reporting