@@ -374,6 +374,7 @@ interface Observable {
374
374
Promise<undefined> forEach(Visitor callback, optional SubscribeOptions options = {});
375
375
Promise<boolean> every(Predicate predicate, optional SubscribeOptions options = {});
376
376
// Maybe? Promise<any> first(optional SubscribeOptions options = {});
377
+ Promise<any> last(optional SubscribeOptions options = {});
377
378
Promise<any> find(Predicate predicate, optional SubscribeOptions options = {});
378
379
Promise<boolean> some(Predicate predicate, optional SubscribeOptions options = {});
379
380
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
1289
1290
1. Return |p|.
1290
1291
</div>
1291
1292
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
+
1292
1338
<div algorithm>
1293
1339
The <dfn for=Observable method><code>find(|predicate|, |options|)</code></dfn> method steps are:
1294
1340
0 commit comments