RxJS skipLast

2020-10-14 10:34 更新

跳過count源 Observable 發(fā)出的最后一個(gè)值。

skipLast<T>(count: number):MonoTypeOperatorFunction<T>

參量

計(jì)數(shù) 從源 Observable 的末尾跳過的元素?cái)?shù)。

returns

MonoTypeOperatorFunction<T>:一個(gè) Observable,它跳過源 Observable 發(fā)出的最后一個(gè)計(jì)數(shù)值。

投擲

ArgumentOutOfRangeError使用時(shí)skipLast(i),如果拋出 ArgumentOutOrRangeError i < 0

描述

skipLast大理石圖

skipLast返回一個(gè) Observable,它累積一個(gè)長(zhǎng)度足以存儲(chǔ)第一個(gè)count值的隊(duì)列。隨著接收到更多的值,將從隊(duì)列的開頭獲取值,并在結(jié)果序列上產(chǎn)生這些值。這導(dǎo)致值被延遲。

跳過包含多個(gè)值的 Observable 的最后 2 個(gè)值

import { range } from 'rxjs';
import { skipLast } from 'rxjs/operators';


const many = range(1, 5);
const skipLastTwo = many.pipe(skipLast(2));
skipLastTwo.subscribe(x => console.log(x));


// Results in:
// 1 2 3

也可以看看

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)