Skip to content

Commit

Permalink
Merge branch 'main' into transcend
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Sep 18, 2023
2 parents 2a76ee5 + 257f4ea commit 5f87ebe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ function* naturals() {
naturals().find(v => v > 1); // 2
```

### `.from(object)`
### `Iterator.from(object)`

`.from` takes an object as an argument. This method allows wrapping "iterator-like" objects with an
iterator.
`.from` is a _static_ method (unlike the others listed above) which takes an object as an argument. This method allows wrapping "iterator-like" objects with an iterator.

Returns the object if it is already an iterator, returns a wrapping iterator if the passed object
implements a callable @@iterator property.
Expand Down
9 changes: 5 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ <h1>
<h1>
GetIteratorFlattenable (
_obj_: an ECMAScript language value,
_stringHandling_: ~iterate-strings~ or ~reject-strings~,
): either a normal completion containing an Iterator Record or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _obj_ is not an Object, throw a *TypeError* exception.
1. If _obj_ is not an Object, then
1. If _stringHandling_ is ~reject-strings~ or _obj_ is not a String, throw a *TypeError* exception.
1. Let _method_ be ? GetMethod(_obj_, @@iterator).
1. If _method_ is *undefined*, then
1. Let _iterator_ be _obj_.
Expand Down Expand Up @@ -187,8 +189,7 @@ <h1>Iterator.prototype</h1>
<emu-clause id="sec-iterator.from">
<h1>Iterator.from ( _O_ )</h1>
<emu-alg>
1. If _O_ is a String, set _O_ to ! ToObject(_O_).
1. Let _iteratorRecord_ be ? GetIteratorFlattenable(_O_).
1. Let _iteratorRecord_ be ? GetIteratorFlattenable(_O_, ~iterate-strings~).
1. Let _hasInstance_ be ? OrdinaryHasInstance(%Iterator%, _iteratorRecord_.[[Iterator]]).
1. If _hasInstance_ is *true*, then
1. Return _iteratorRecord_.[[Iterator]].
Expand Down Expand Up @@ -443,7 +444,7 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
1. Let _value_ be ? IteratorValue(_next_).
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_mapped_, _iterated_).
1. Let _innerIterator_ be Completion(GetIteratorFlattenable(_mapped_)).
1. Let _innerIterator_ be Completion(GetIteratorFlattenable(_mapped_, ~reject-strings~)).
1. IfAbruptCloseIterator(_innerIterator_, _iterated_).
1. Let _innerAlive_ be *true*.
1. Repeat, while _innerAlive_ is *true*,
Expand Down

0 comments on commit 5f87ebe

Please sign in to comment.