# list-fn A generic lazy list. It's an immutable iterator with continuations. The lazy list can be used as an immutable alternative to the standard Rust iterator. Any `List` is an iterator. Any `&mut Iterator` is a `List`. See also [Generators](https://doc.rust-lang.org/std/ops/trait.Generator.html). ## Fundamental Operations - `FlatScan`. An order of items is important. - `FilterScan` - `Scan` - `Fold` - `FlatMap`. An order of items is not important. - `Map` - `Filter` - `Flatten` ## Evolution ### 1. Iterator ```rust trait Iterator { type Item; fn next(&mut self) -> Option; } trait IteratorReturn: Iterator { type Return; fn return(&mut self) -> Return; } ``` ### 2. Generator ```rust trait Generator { type Yield; type Return; fn resume(&mut self) -> GeneratorState; } enum GeneratorState { Yielded(Y), Complete(R), } ``` ### 3. List ```rust trait List { type Yield; type Return; fn resume(self) -> ListState; } enum ListState { Yielded(L::Yield, L), Return(L::Return), } ``` ## FlatScan ### 3. List ```rust trait FlatScan { type InputYield; type InputReturn; type OutputYield; type OutputReturn; fn map_yield(self, input_yield: Self::InputYield) -> impl List; fn map_return(self, input_return: Self::InputReturn) -> impl List; } ``` ### 2. Generator ```rust trait FlatScan { type InputYield; type InputReturn; type OutputYield; type OutputReturn; fn map_yield(&mut self, input_yield: Self::InputYield) -> impl Iterator; fn map_return(&mut self, input_return: Self::InputReturn) -> impl Generator; } ``` ### 1. Iterator ```rust trait FlatScan { type InputYield; type InputReturn; type OutputYield; type OutputReturn; fn map_yield(&mut self, input_yield: Self::InputYield) -> impl Iterator; fn map_return(&mut self, input_return: Self::InputReturn) -> impl Iterator + IteratorReturn; } ```