Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec the last() operator #133

Merged
merged 2 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ interface Observable {
Promise<undefined> forEach(Visitor callback, optional SubscribeOptions options = {});
Promise<boolean> every(Predicate predicate, optional SubscribeOptions options = {});
// Maybe? Promise<any> first(optional SubscribeOptions options = {});
Promise<any> last(optional SubscribeOptions options = {});
Promise<any> find(Predicate predicate, optional SubscribeOptions options = {});
Promise<boolean> some(Predicate predicate, optional SubscribeOptions options = {});
Promise<any> reduce(Reducer reducer, optional any initialValue, optional SubscribeOptions options = {});
Expand Down Expand Up @@ -1101,6 +1102,51 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
1. <span class=XXX>TODO: Spec this and use |predicate| and |options|.</span>
</div>

<div algorithm>
The <dfn for=Observable method><code>last(|options|)</code></dfn> method steps are:

1. Let |p| [=a new promise=].

1. If |options|'s {{SubscribeOptions/signal}} is not null:

1. If |options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then:

1. [=Reject=] |p| with |options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
reason=].

1. Return |p|.

1. [=AbortSignal/add|Add the following abort algorithm=] to |options|'s
{{SubscribeOptions/signal}}:

1. [=Reject=] |p| with |options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
reason=].

1. Let |lastValue| be an {{any}}-or-null, initially null.

1. Let |hasLastValue| be a [=boolean=], initially false.

1. Let |observer| be a new [=internal observer=], initialized as follows:

: [=internal observer/next steps=]
:: 1. Set |hasLastValue| to true.

1. Set |lastValue| to the passed in <var ignore>value</var>.

: [=internal observer/error steps=]
:: [=Reject=] |p| with the passed in <var ignore>error</var>.

: [=internal observer/complete steps=]
:: 1. If |hasLastValue| is true, [=resolve=] |p| with |lastValue|.

1. Otherwise, [=reject=] |p| with a [=new=] {{RangeError}}.

1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to [=this=] given |observer|
and |options|.

1. Return |p|.
</div>

<div algorithm>
The <dfn for=Observable method><code>find(|predicate|, |options|)</code></dfn> method steps are:

Expand Down
Loading