Skip to content

Commit e6ee22b

Browse files
domfarolinobenlesh
andauthored
Spec the last() operator (#133)
* Spec the `last()` operator * Account for observables that only emit null values --------- Co-authored-by: Ben Lesh <[email protected]>
1 parent 8895adc commit e6ee22b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

spec.bs

+46
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ interface Observable {
374374
Promise<undefined> forEach(Visitor callback, optional SubscribeOptions options = {});
375375
Promise<boolean> every(Predicate predicate, optional SubscribeOptions options = {});
376376
// Maybe? Promise<any> first(optional SubscribeOptions options = {});
377+
Promise<any> last(optional SubscribeOptions options = {});
377378
Promise<any> find(Predicate predicate, optional SubscribeOptions options = {});
378379
Promise<boolean> some(Predicate predicate, optional SubscribeOptions options = {});
379380
Promise<any> reduce(Reducer reducer, optional any initialValue, optional SubscribeOptions options = {});
@@ -1289,6 +1290,51 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
12891290
1. Return |p|.
12901291
</div>
12911292

1293+
<div algorithm>
1294+
The <dfn for=Observable method><code>last(|options|)</code></dfn> method steps are:
1295+
1296+
1. Let |p| [=a new promise=].
1297+
1298+
1. If |options|'s {{SubscribeOptions/signal}} is not null:
1299+
1300+
1. If |options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then:
1301+
1302+
1. [=Reject=] |p| with |options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
1303+
reason=].
1304+
1305+
1. Return |p|.
1306+
1307+
1. [=AbortSignal/add|Add the following abort algorithm=] to |options|'s
1308+
{{SubscribeOptions/signal}}:
1309+
1310+
1. [=Reject=] |p| with |options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
1311+
reason=].
1312+
1313+
1. Let |lastValue| be an {{any}}-or-null, initially null.
1314+
1315+
1. Let |hasLastValue| be a [=boolean=], initially false.
1316+
1317+
1. Let |observer| be a new [=internal observer=], initialized as follows:
1318+
1319+
: [=internal observer/next steps=]
1320+
:: 1. Set |hasLastValue| to true.
1321+
1322+
1. Set |lastValue| to the passed in <var ignore>value</var>.
1323+
1324+
: [=internal observer/error steps=]
1325+
:: [=Reject=] |p| with the passed in <var ignore>error</var>.
1326+
1327+
: [=internal observer/complete steps=]
1328+
:: 1. If |hasLastValue| is true, [=resolve=] |p| with |lastValue|.
1329+
1330+
1. Otherwise, [=reject=] |p| with a [=new=] {{RangeError}}.
1331+
1332+
1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to [=this=] given |observer|
1333+
and |options|.
1334+
1335+
1. Return |p|.
1336+
</div>
1337+
12921338
<div algorithm>
12931339
The <dfn for=Observable method><code>find(|predicate|, |options|)</code></dfn> method steps are:
12941340

0 commit comments

Comments
 (0)