仅在另一个可观察到

发布于 2025-02-08 17:16:04 字数 422 浏览 2 评论 0原文

我有代码的工作:

import { of } from 'rxjs';
import { map, takeWhile } from 'rxjs/operators';

const stream$ = of(3, 2, 1, 0, -1, -2, -3);

const ready$ = stream$.pipe(takeWhile((data) => data !== 0));

ready$.subscribe(console.log)

它将记录3、2、1。

如何创建一个可观察到的可观的$ stream值,但仅在0之后才得出。

换句话说:当准备就绪$完成时,如何使可观察到流$的值可观察到3、2、1、0?

I have working pieace of code:

import { of } from 'rxjs';
import { map, takeWhile } from 'rxjs/operators';

const stream$ = of(3, 2, 1, 0, -1, -2, -3);

const ready$ = stream$.pipe(takeWhile((data) => data !== 0));

ready$.subscribe(console.log)

It will log 3, 2, 1.

How to create an observable that emmits all $stream values but only after 0 is emmited.

In other words: when ready$ completes, how to have observable that emmits values of stream$ except 3, 2, 1, 0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉 2025-02-15 17:16:07

您只需要用 skipwhile替换,然后添加额外的skip(1)才能忽略0

const ready$ = stream$.pipe(skipWhile((data) => data !== 0),skip(1));

You just have to replace takeWhile with skipWhile and add an extra skip(1) to ignore 0

const ready$ = stream$.pipe(skipWhile((data) => data !== 0),skip(1));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文