kotlin - 使用协程通道时,如何激活 -> 运算符?
问题描述
在此示例中,https://kotlinlang.org/docs/channels.html#prime-numbers-with-pipeline
我们有两个函数:
fun CoroutineScope.numbersFrom(start: Int) = produce<Int> {
var x = start
while (true) send(x++) // infinite stream of integers from start
}
fun CoroutineScope.filter(numbers: ReceiveChannel<Int>, prime: Int) = produce<Int> {
for (x in numbers) if (x % prime != 0) send(x)
}
但是,该示例无法编译
numbersFrom(2) -> filter(2) -> filter(3) -> filter(5) -> filter(7)
我得到的编译错误是Expecting comma or ')'
有没有我忘记使用的导入。我到目前为止的进口是
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce
解决方案
推荐阅读
- function - 检查 2 个文件位置中的文件的功能不起作用
- javascript - 粒子 JS 的问题
- python - boto3 s3 api 在调用 GetBucketPolicyStatus 操作时失败并显示“(NoSuchBucketPolicy)”
- c# - 新插入的记录是否可用于同一事务中的后续 SQL 命令?
- autodesk-forge - 文件夹权限批量更新端点返回“访问被拒绝”错误
- c - 尝试扫描并打印结构中的字符串
- java - Swagger-Core 的对立面?
- spring-boot - 为什么我的 Spring Boot 单元测试不会在服务类中加载 @Value 属性?
- python - Python - 带有 STDIN 和 STDOUT 的子进程
- pine-script - 如何使用 Pine 脚本在监视列表中选择符号