dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Follow Iterators and Generators pattern with the `next` helpers

Open nolde opened this issue 4 years ago • 1 comments

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators

In JavaScript an iterator is an object which defines a sequence and potentially a return value upon its termination.

Specifically, an iterator is any object which implements the Iterator protocol by having a next() method that returns an object with two properties:

  • value
    • The next value in the iteration sequence.
  • done
    • This is true if the last value in the sequence has already been consumed. If value is present alongside done, it is the iterator's return value.

Once created, an iterator object can be iterated explicitly by repeatedly calling next(). Iterating over an iterator is said to consume the iterator, because it is generally only possible to do once. After a terminating value has been yielded additional calls to next() should continue to return {done: true}.

nolde avatar May 25 '21 03:05 nolde

Another good explanation on iterators: https://javascript.info/iterable

braekevelt avatar Jan 05 '22 17:01 braekevelt