Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 完成流并发出最后一个值_Javascript_Rxjs - Fatal编程技术网

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=>total
takeWhile
应该可以做到这一点

imitationsOfClientConnection.pipe(
  scan((result, current) => result + current, 0),
  takeWhile(total => total <= MAX_VALUE)
).subscribe(//...
模仿客户端连接.pipe(
扫描((结果,电流)=>结果+电流,0),

takeWhile(total=>total你真的试过了吗?你真的试过了吗?