with a recursive function - Simple - The most efficient single element Seq Weaknesses: - O(n) size and append operations - Huge memory overheads (20 bytes/element) - Cache/GC unfriendly memory layout - map allocates n new objects 14/30
O(1) - Cheap append and prepend Weaknesses: - Doesn’t implement Seq - Unpredictable performance due to wrapping - High memory overheads without wrapping 16/30
Good map/filter/… performance - Low memory overheads (~0.8 bytes / element) - Moderate amount of allocations - Good performance in most scenarios Weaknesses: - primitive types need to be wrapped - constructing Vector element-by-element is slower (than a List) 25/30
in teaching - Immutability and structural sharing - Recursion - Standard library uses List as default Seq - Cats prefer List (e.g. Reducable#toList, Applicative#replicateA) - Because Haskel? 27/30
Use List, ArraySeq, ..., where their advantage is obvious 3. Specify precise collection type Use Seq only if needed and without impact on performance 4. Monitor performance in production. Profile hot paths. Optimise accordingly. 29/30