diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-21 05:33:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-21 05:33:16 +0100 |
| commit | 801a25abc1899df538939a8c2a3907bbea62cf1c (patch) | |
| tree | 35bd7295c566320cbc5b316805357ca4679f6cca /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs | |
| parent | ef7c8a158f5bb36e3f5b96eacc196061e8ab9d10 (diff) | |
| parent | 121bffce8106a73b90eb4f68da42d4d7ceca5375 (diff) | |
| download | rust-801a25abc1899df538939a8c2a3907bbea62cf1c.tar.gz rust-801a25abc1899df538939a8c2a3907bbea62cf1c.zip | |
Rollup merge of #69997 - WaffleLapkin:option_zip, r=LukasKalbertodt
add `Option::{zip,zip_with}` methods under "option_zip" gate
This PR introduces 2 methods - `Option::zip` and `Option::zip_with` with
respective signatures:
- zip: `(Option<T>, Option<U>) -> Option<(T, U)>`
- zip_with: `(Option<T>, Option<U>, (T, U) -> R) -> Option<R>`
Both are under the feature gate "option_zip".
I'm not sure about the name "zip", maybe we can find a better name for this.
(I would prefer `union` for example, but this is a keyword :( )
--------------------------------------------------------------------------------
Recently in a russian rust begginers telegram chat a newbie asked (translated):
> Are there any methods for these conversions:
>
> 1. `(Option<A>, Option<B>) -> Option<(A, B)>`
> 2. `Vec<Option<T>> -> Option<Vec<T>>`
>
> ?
While second (2.) is clearly `vec.into_iter().collect::<Option<Vec<_>>()`, the
first one isn't that clear.
I couldn't find anything similar in the `core` and I've come to this solution:
```rust
let tuple: (Option<A>, Option<B>) = ...;
let res: Option<(A, B)> = tuple.0.and_then(|a| tuple.1.map(|b| (a, b)));
```
However this solution isn't "nice" (same for just `match`/`if let`), so I thought
that this functionality should be in `core`.
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions
