知识卡片
惰性适配器组合处理
map 描述如何转换元素,filter 描述保留条件,它们先形成新的惰性迭代器。闭包可捕获局部变量来参数化处理,例如根据 shoe_size 保留匹配项。需要实际执行时,使用 collect 等消费操作。
相关卡片 [[闭包携带执行环境]]、[[消费迭代器产生结果]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 函数式语言特性:迭代器与闭包 Methods That Consume the Iterator · 查看原书依据
You can chain multiple calls to iterator adapters to perform complex actions in a readable way. But because all iterators are lazy, you have to call one of the consuming adapter methods to get results from calls to iterator adapters.
参考来源
- 位置:《The Rust Programming Language(第2版)》第13章 函数式语言特性:迭代器与闭包(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c13.xhtml`,块 0140)
- 结论依据:原文说明适配器能链接,消费端请求数据后才得到结果。
- 原始内容:You can chain multiple calls to iterator adapters to perform complex actions in a readable way. But because all iterators are lazy, you have to call one of the consuming adapter methods to get results from calls to iterator adapters.