Skip to content

Commit

Permalink
Type Iterator.from
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hull committed Nov 22, 2024
1 parent efe3518 commit 387de8b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,16 @@ interface $Iterable<+Yield,+Return,-Next> {
}
type Iterable<+T> = $Iterable<T,void,void>;

interface IteratorConstructor {
/**
* This method allows wrapping "iterator-like" objects with an iterator.
* @returns The argument object if it's already an iterator, or a wrapping iterator if the passed object implements a callable @@iterator property.
*/
from<+Yield,+Return,-Next>(source: $Iterable<Yield,Return,Next>): $Iterator<Yield,Return,Next>;
}

declare var Iterator: IteratorConstructor;

interface Generator<+Yield,+Return,-Next> {
@@iterator(): $Iterator<Yield,Return,Next>;
next(value?: Next): IteratorResult<Yield,Return>;
Expand Down
3 changes: 3 additions & 0 deletions tests/iterator_helpers/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options]
no_flowlib=false
all=true
2 changes: 2 additions & 0 deletions tests/iterator_helpers/from.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* @flow */
(Iterator.from([1]): Iterator<number>);
1 change: 1 addition & 0 deletions tests/iterator_helpers/iterator_helpers.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Found 0 errors

0 comments on commit 387de8b

Please sign in to comment.