This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ <h1>GetIteratorDirect ( _obj_ )</h1> | |
<emu-alg> | ||
1. If Type(_obj_) is not Object, throw a *TypeError* exception. | ||
1. Let _nextMethod_ be ? GetV(_obj_, `"next"`). | ||
1. If IsCallable(_nextMethod_) is *false*, throw a *TypeError* exception. | ||
1. Let _iteratorRecord_ be Record { [[Iterator]]: _obj_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }. | ||
1. Return _iteratorRecord_. | ||
</emu-alg> | ||
|
@@ -314,6 +315,35 @@ <h1>%Iterator.prototype%.asIndexedPairs ( )</h1> | |
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id="sec-iteratorprototype-flatmap"> | ||
<h1>%Iterator.prototype%.flatMap ( _mapper_ )</h1> | ||
<p>%Iterator.prototype%.flatMap is a built-in generator function which, when called, performs the following steps:</p> | ||
<emu-alg> | ||
1. Let _iterated_ be ? GetIteratorDirect(*this* value). | ||
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception. | ||
</emu-alg> | ||
<p>The body of %Iterator.prototype%.flatMap is composed of the following steps:</p> | ||
<emu-alg> | ||
1. Repeat, | ||
1. Let _next_ be ? IteratorNext(_iterated_). | ||
1. If _next_ is *false*, return *undefined*. | ||
1. Let _value_ be ? IteratorValue(_next_). | ||
1. Let _mapped_ be ? Call(_mapper_, *undefined*, « _value_ »). | ||
1. Let _usingIterator_ be ? Get(_mapped_, @@iterator). | ||
1. If _usingIterator_ is *undefined*, then | ||
1. Perform ? Yield(_mapped_). | ||
1. Else, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ljharb
Member
|
||
1. Let _innerIterator_ be ? GetIterator(_mapped_, ~sync~, _usingIterator_). | ||
1. Let _innerAlive_ be *true*. | ||
1. Repeat, while _innerAlive_ is *true*, | ||
1. Let _innerNext_ be ? IteratorNext(_innerIterator_). | ||
1. If next is *false*, set _innerAlive_ to *false*. | ||
1. Else, | ||
1. Let _innerValue_ be ? IteratorNext(_innerNext_). | ||
1. Perform ? Yield(_innerValue_). | ||
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id="sec-iteratorprototype-reduce"> | ||
<h1>%Iterator.prototype%.reduce ( _reducer_ [ , _initialValue_ ] )</h1> | ||
<emu-alg> | ||
|
1 comment
on commit 8373112
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why the results of yield
are not handled, unlike other methods?
Get
works only on objects, so we are not able to return a primitive frommapper
- inconsistency withArray#flatMap
. Strings are iterable, so they also will be flattened.