Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

/// <reference types="@stdlib/types"/>

import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite what we want. We can actually improve type specificity here and in other similar packages in a few ways:

  1. The union is correct insofar as the function accepts both iterators and iterable iterators.
  2. The output iterator should be typed, as it always returns numbers.
  3. We should likely type the input iterator, as well, since it should return numbers.
  4. Via the union, we can use generics where T extends the union and we return T. That should cover both the iterator and iterable iterator behavior mentioned in the notes for those environments supporting Symbol.iterator.


// Define a union type representing both iterable and non-iterable iterators:
type Iterator = Iter | IterableIterator;
import { Iterator } from '@stdlib/types/iter';

/**
* Returns an iterator which iteratively computes a cumulative arithmetic geometric mean.
Expand Down