-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Mapping booleans to Option #50523
Copy link
Copy link
Closed
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
In a decent number of situations, I end up finding myself writing code like:
This happens especially in closures passed to
Iterator::filter_map, but I also frequently find that I want this in.and_then(e.g., on futures). For cases like these, it'd be very handy to have a concise way of turning booleans intoOptions. For example:There could also be closure variants of this for cases where the
Tis expensive to construct, but in my experience those cases are rarer. That would let the code above become:The name could of course be bikeshed (
if_true?), but I think this is a pretty versatile and useful shorthand!