← 返回刚才阅读的位置

知识卡片

操作参考卡 · 743.d.6.b

迭代范围与顺序可组合控制

理解等级:中级

take(n)最多取n项,skip(n)跳过前n项,step_by(n)按步长取项;chain先后连接,cycle重复,rev反向。不同适配器有各自前提,例如rev需双端迭代,cycle需可克隆以重新开始。顺序与终止条件属于行为契约,不应为缩短代码随意调换。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Iterator Transforms · 查看原书依据

      take(n) Restricts an iterator to emitting at most n items. skip(n) Skips over the first n elements of the iterator. step_by(n) Converts an iterator so it emits only every nth item. chain(other) Glues together two iterators, to build a combined iterator that moves through one then the other. cycle() Converts an iterator that terminates into one that repeats f

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Iterator Transforms》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u049-ch01-074)。 - 结论依据:原文在“take(n)”附近的定义、例子或代码支撑本卡核心说明:take(n)最多取n项,skip(n)跳过前n项,step_by(n)按步长取项;chain先后连接,cycle重复,rev反向。边界按已读前提解释;示例未执行。 - 原始内容:take(n) Restricts an iterator to emitting at most n items. skip(n) Skips over the first n elements of the iterator. step_by(n) Converts an iterator so it emits only every nth item. chain(other) Glues together two iterators, to build a combined iterator that moves through one then the other. cycle() Converts an iterator that terminates into one that repeats f