知识卡片

操作参考卡 · 743.d.6.a.3

查找与判定可以短路

理解等级:中级

find返回首个匹配值,position返回当前迭代流中的位置,nth按从零开始的序号取项;any遇到真即可结束,all遇到假即可结束。短路后剩余项不一定被处理,因此有副作用的闭包不能假定每项都会执行。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

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

      any(p) Indicates whether a predicate is true for any item in the collection. all(p) Indicates whether a predicate is true for all items in the collection. In either case, iteration will terminate early if the relevant counterexample is found. There are methods that allow for the possibility of failure in the closures used with each item. In each case, if a c

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Iterator Consumers》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u050-ch01-078)。 - 结论依据:原文在“any(p)”附近的定义、例子或代码支撑本卡核心说明:find返回首个匹配值,position返回当前迭代流中的位置,nth按从零开始的序号取项;any遇到真即可结束,all遇到假即可结束。边界按已读前提解释;示例未执行。 - 原始内容:any(p) Indicates whether a predicate is true for any item in the collection. all(p) Indicates whether a predicate is true for all items in the collection. In either case, iteration will terminate early if the relevant counterexample is found. There are methods that allow for the possibility of failure in the closures used with each item. In each case, if a c