subspace icon indicating copy to clipboard operation
subspace copied to clipboard

Iterator::collect should ideally support conversions #425

Open Ananyasingh2002 opened this issue 2 years ago • 6 comments

Resolved the issue#425 with collecting Iterator<const std::string&> into Vecstd::string. Implemented map(|s| s.to_owned()) to convert constant references in the iterator to owned std::strings. This transformation rectified the mismatch, allowing successful collection into Vecstd::string. The adjustment eliminates the need for .cloned() and ensures compatibility with the copy constructible type.

Ananyasingh2002 avatar Jan 01 '24 08:01 Ananyasingh2002

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Jan 01 '24 08:01 google-cla[bot]

@Ananyasingh2002 you need to sign the CLA first to make the workflow run.

Neilblaze avatar Jan 01 '24 12:01 Neilblaze

Hello @Neilblaze, It seems there's an issue preventing me from signing the Contributor License Agreement (CLA). The message indicates a server error, advising me to retry the request.

Ananyasingh2002 avatar Jan 01 '24 15:01 Ananyasingh2002

can we create a new data structure or a new collect function that will support conversion to different conversion

Pratik9113 avatar Jan 04 '24 20:01 Pratik9113

I am a bit confused about this PR. It seems to be assuming the collect function is doing conversion already?

The issue is that IntoIterator (and thus collect) requires the into_iter() function's returned Iterator::Item type to be exactly the same as the type specified in IntoIterator. But I believe it would be better here to match an Iterator::Item type if its convertible-to the type in IntoIterator.

Some options:

  • Maybe collect needs to use a more lenient version of IntoIterator, and perform a map itself when the types don't match.
  • Maybe Iterator<T> can match a concrete type if its Item is convertible-to T since next() returning a T will be valid in code that wants something T converts to as well.

I will copy these thoughts to the issue.

danakj avatar Jan 05 '24 15:01 danakj

Haven't heard anything in a bit here, will you be coming back to it?

danakj avatar Feb 20 '24 18:02 danakj