list-fn

Crates.iolist-fn
lib.rslist-fn
version0.20.1
sourcesrc
created_at2021-04-07 18:30:37.460473
updated_at2023-10-27 19:19:09.596768
descriptionA generic lazy list
homepage
repositoryhttps://github.com/natfoam/lib
max_upload_size
id380507
size25,683
Sergey Shandar (sergey-shandar)

documentation

README

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<End = Self> is an iterator. Any &mut Iterator is a List<End = Self>.

See also Generators.

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

trait Iterator {
  type Item;
  fn next(&mut self) -> Option<Self::Item>;
}

trait IteratorReturn: Iterator {
  type Return;
  fn return(&mut self) -> Return;
}

2. Generator

trait Generator {
  type Yield;
  type Return;
  fn resume(&mut self) -> GeneratorState<Self::Yield, Self::Return>;
}

enum GeneratorState<Y, R> {
  Yielded(Y),
  Complete(R),
}

3. List

trait List {
  type Yield;
  type Return;
  fn resume(self) -> ListState<Self>;
}

enum ListState<L: List> {
  Yielded(L::Yield, L),
  Return(L::Return),
}

FlatScan

3. List

trait FlatScan {
  type InputYield;
  type InputReturn;
  type OutputYield;
  type OutputReturn;
  fn map_yield(self, input_yield: Self::InputYield) -> impl List<Yield = Self::OutputYield, Return = Self>;
  fn map_return(self, input_return: Self::InputReturn) -> impl List<Yield = Self::OutputYield, Return = OutputReturn>;
}

2. Generator

trait FlatScan {
  type InputYield;
  type InputReturn;
  type OutputYield;
  type OutputReturn;
  fn map_yield(&mut self, input_yield: Self::InputYield) -> impl Iterator<Item = Self::OutputYield>;
  fn map_return(&mut self, input_return: Self::InputReturn) -> 
    impl Generator<Item = Self::OutputYield, Return = Self::OutputReturn>;
}

1. Iterator

trait FlatScan {
  type InputYield;
  type InputReturn;
  type OutputYield;
  type OutputReturn;
  fn map_yield(&mut self, input_yield: Self::InputYield) -> impl Iterator<Item = Self::OutputYield>;
  fn map_return(&mut self, input_return: Self::InputReturn) -> 
    impl Iterator<Item = Self::OutputYield> + IteratorReturn<Return = Self::OutputReturn>;
}
Commit count: 212

cargo fmt