Skip to content

Releases: T99/iter-over

Fixed Iterator Type

27 Aug 15:49
@T99 T99
Compare
Choose a tag to compare

After changes made for the v2.0.0 release, the type being returned for [Symbol.iterator] included undefined in the type union for the iterator result. This caused users to have to cast iteration results to their intended type:

for (person of new PersonIterator(people)) {
    let person: Person = person as Person;
}

Otherwise, TypeScript would complain that Person | undefined could not be assigned to a variable of type Person.

Added `AsyncIterator`

25 Aug 02:38
@T99 T99
Compare
Choose a tag to compare

Added the AsyncIterator class to support the (somewhat) new [Symbol.asyncIterator] protocol. This new class allows for iteration over an array of Promises using the for await syntax:

async function fetchWeatherForCity(city: string): Promise<WeatherData> { ... }

let weatherAsyncIterable: AsyncIterable<WeatherData> = new AsyncIterable([
    fetchWeatherForCity("Chicago"),
    fetchWeatherForCity("New York"),
    fetchWeatherForCity("Seattle"),
    fetchWeatherForCity("Miami")
]);

for await (weatherData of weatherAsyncIterable) {
    console.log(`${weatherData.location}: ${weatherData.temperature}`);
}

The above code would print out the temperature in each city, as the data becomes available. This is to say that if whatever API we are using to get weather data responds with data for Seattle in 500ms, but then takes 4 seconds to return us data for Chicago, the Seattle data will be printed as soon as it becomes available, and the same goes for the Chicago data.

The above code is akin to doing something like the following:

async function fetchWeatherForCity(city: string): Promise<WeatherData> { ... }

let weatherDataPromises: Promise<any>[] = [
    fetchWeatherForCity("Chicago"),
    fetchWeatherForCity("New York"),
    fetchWeatherForCity("Seattle"),
    fetchWeatherForCity("Miami")
];

weatherDataPromises.forEach((weatherDataPromise: Promise<WeatherData>): void => {
    console.log(`${weatherData.location}: ${weatherData.temperature}`);
});

await Promise.all(weatherDataPromises);

But who doesn't like using new shiny syntax? 😄

Find it now on NPM.

Addition of Inline Documentation

05 Oct 20:47
@T99 T99
Compare
Choose a tag to compare
Added documentation and #getIterableIterator method.

Also modified return type of base #next method.

The Renaming

11 Jun 12:28
@T99 T99
Compare
Choose a tag to compare

After working with importing my own modules from NPM more, I've realized that prefixing the files I'd published wasn't really convention or even all that useful in the end. Files have been renamed accordingly.

  • IOAIteratorAbstractIterator
  • IOIIteratorIIterator
  • IOStringIteratorStringIterator
  • IOEmptyIteratorEmptyIterator
  • IOObjectIteratorObjectIterator
  • IOKeyValuePairKeyValuePair

Find this version on NPM.

Initial Release

11 Jun 04:22
@T99 T99
Compare
Choose a tag to compare

This is the first working version to be live and available on NPM, including the following classes:

  • IOAIterator
  • IOIIterator
  • IOStringIterator
  • IOEmptyIterator
  • IOObjectIterator
  • IOKeyValuePair

Find this version on NPM.