知识卡片
用迭代链表达查询意图
按数据流写 lines().filter(谓词).collect(),源码直接体现筛选目标,闭包保留唯一随需求变动的测试条件。Rust 仍逐项推进,只是位置推进、保留逻辑和收集交给适配器组合。
相关卡片 [[惰性适配器组合处理]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 函数式语言特性:迭代器与闭包 Making Code Clearer with Iterator Adapters · 查看原书依据
The next logical question is which style you should choose in your own code and why: the original implementation in Listing 13-21 or the version using iterators in Listing 13-22. Most Rust programmers prefer to use the iterator style.
参考来源
- 位置:《The Rust Programming Language(第2版)》第13章 函数式语言特性:迭代器与闭包(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c13.xhtml`,块 0196)
- 结论依据:原文比较显式循环和适配器写法,指出后者突出了筛选条件。
- 原始内容:The next logical question is which style you should choose in your own code and why: the original implementation in Listing 13-21 or the version using iterators in Listing 13-22. Most Rust programmers prefer to use the iterator style.