mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-11 07:21:51 +00:00
Merge #9840
9840: minor: reword a bit r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
62c8572608
@ -927,7 +927,7 @@ Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, a
|
|||||||
|
|
||||||
## Functional Combinators
|
## Functional Combinators
|
||||||
|
|
||||||
Use high order monadic combinators like `map`, `then`, only when they are a natural choice, don't bend the code to fit into some combinator.
|
Use high order monadic combinators like `map`, `then` when they are a natural choice; don't bend the code to fit into some combinator.
|
||||||
If writing a chain of combinators creates friction, replace them with control flow constructs: `for`, `if`, `match`.
|
If writing a chain of combinators creates friction, replace them with control flow constructs: `for`, `if`, `match`.
|
||||||
Mostly avoid `bool::then` and `Option::filter`.
|
Mostly avoid `bool::then` and `Option::filter`.
|
||||||
|
|
||||||
@ -944,7 +944,7 @@ Some(x).filter(|it| it.cond())
|
|||||||
|
|
||||||
This rule is more "soft" then others, and boils down mostly to taste.
|
This rule is more "soft" then others, and boils down mostly to taste.
|
||||||
The guiding principle behind this rule is that code should be dense in computation, and sparse in the number of expressions per line.
|
The guiding principle behind this rule is that code should be dense in computation, and sparse in the number of expressions per line.
|
||||||
The second example contains *less* computation -- `filter` function is an indirection for `if`, it doesn't do any useful work by itself.
|
The second example contains *less* computation -- the `filter` function is an indirection for `if`, it doesn't do any useful work by itself.
|
||||||
At the same time, it is more crowded -- it takes more time to visually scan it.
|
At the same time, it is more crowded -- it takes more time to visually scan it.
|
||||||
|
|
||||||
**Rationale:** consistency, playing to language's strengths.
|
**Rationale:** consistency, playing to language's strengths.
|
||||||
|
Loading…
Reference in New Issue
Block a user