Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

takeLast

Waits for the source to complete, then emits the last N values from the source, as specified by the count argument.

takeLast results in an observable that will hold values up to count values in memory, until the source completes. It then pushes all values in memory to the consumer, in the order they were received from the source, then notifies the consumer that it is complete.

If for some reason the source completes before the count supplied to takeLast is reached, all values received until that point are emitted, and then completion is notified.

Warning: Using takeLast with an observable that never completes will result in an observable that never emits a value.

Example

Take the last 3 values of an Observable with many values

import { range, takeLast } from 'rxjs';

const many = range(1, 100);
const lastThree = many.pipe(takeLast(3));
lastThree.subscribe(x => console.log(x));
function takeLast<T>(count: number): MonoTypeOperatorFunction<T>;
§
takeLast<T>(count: number): MonoTypeOperatorFunction<T>
[src]

§Type Parameters

§Parameters

§
count: number
[src]

The maximum number of values to emit from the end of the sequence of values emitted by the source Observable.

§Return Type

§

A function that returns an Observable that emits at most the last count values emitted by the source Observable.