710 B
710 B
obj |
---|
concept |
Iterator Pattern
Description:
The Iterator Pattern is a behavioral design pattern that provides a way to access the elements of a collection sequentially without exposing its underlying representation. It defines a common interface for iterating over various types of collections, such as arrays, lists, trees, and more. The pattern separates the responsibility of iteration from the collection itself, promoting encapsulation and flexibility.
Example:
Rust has iterators which can be extended by functional programming methods like map()
, etc.
trait Iterator<T> {
fn has_next(&self) -> bool;
fn next(&mut self) -> Option<T>;
}