What it is not so good for

One obvious drawback of our implementation, which shows a possible problem with the iteration design pattern, is its use in parallel code. What would happen if another thread adds or removes objects to or from the original collection? Our iterator will not reflect that and it could lead to problems due to lack of synchronization. Making iterators capable of handling multithreaded environments is not a simple task.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.