Javascript 完成流并发出最后一个值
如何按条件完成流,同时辐射完成的流的值Javascript 完成流并发出最后一个值,javascript,rxjs,Javascript,Rxjs,如何按条件完成流,同时辐射完成的流的值 const MAX_VALUE = 6; const competePredicate = data => data <= MAX_VALUE; let imitationsOfClientConnection = of( 0, 1, 2, 3, 4, 5 ); imitationsOfClientConnection.pipe( scan((result, current) => result + current, 0),
const MAX_VALUE = 6;
const competePredicate = data => data <= MAX_VALUE;
let imitationsOfClientConnection = of( 0, 1, 2, 3, 4, 5 );
imitationsOfClientConnection.pipe(
scan((result, current) => result + current, 0),
// <- what to write here?
).subscribe({
next: data => console.log(`You won: ${ data } points!`),
complete: () => console.log('complete')
});
const MAX_值=6;
常量谓词=数据=>数据结果+当前值,0),
//log(`youwind:${data}点!`),
complete:()=>console.log('complete')
});
现在控制台的输出是-
你赢了:0分你赢了:1分! 你赢了:3分! 你赢了:6分
你赢了:10分
你赢了:15分
完整的 您需要将输出写入控制台的代码如下- 你赢了:0分
你赢了:1分
你赢了:3分! 你赢了:6分
完整的
takeWhile
应该可以做到这一点
imitationsOfClientConnection.pipe(
scan((result, current) => result + current, 0),
takeWhile(total => total <= MAX_VALUE)
).subscribe(//...
模仿客户端连接.pipe(
扫描((结果,电流)=>结果+电流,0),
takeWhile(total=>totaltakeWhile
应该可以做到这一点
imitationsOfClientConnection.pipe(
scan((result, current) => result + current, 0),
takeWhile(total => total <= MAX_VALUE)
).subscribe(//...
模仿客户端连接.pipe(
扫描((结果,电流)=>结果+电流,0),
takeWhile(total=>total你真的试过了吗?你真的试过了吗?