You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this change is still active, but I've stumbled upon a use case where a broader version of this for iterators in general, rather than strictly for arrays, would be useful. Is that something worth considering?
I'm totally new to both Rust contributions & open source in general, so I'm not sure if the idea of a general try_map is worth considering/pursuing, but I just thought I'd throw the idea out there since I thought it would be useful. Appreciate any feedback & insights!
(And, if it gets to that point, I'd be interested in taking a stab at implementing it. Would love to make a contribution to Rust, no matter how small!)
+1 for this one, it's the only way I found to run a fallible .map() without collecting to a Vec, and still use Try afterward, which leads to a concise and straightforward code.
Not sure if this change is still active, but I've stumbled upon a use case where a broader version of this for iterators in general, rather than strictly for arrays, would be useful.
I guess that's what iter.collect::<Result<_>>() and the unstable iter.try_collect() are intended for.
Reacted by Demo for summer'23 and Wessel Kronemeijer
Note that this, like array::try_from_fn and Iterator::try_find and similar, depends on the Residual trait mechanism for mapping from Foo<A> to Foo<[A; N]>, which is not used in any stable functions right now, so stabilization here is a bigger question than just the specific function in question.
See #94119 (comment) where array::from_fn was accepted but array::try_from_fn wasn't accepted due to this.
Right, stabilizing try_map doesn't require stabilizing Residual itself, but it does expose it, which is itself a commitment to have something like it forever.
Thank you for the replies! As far as I understood, there is a consensus that exposing Try trait in stable APIs is ok (e.g. Iterator::try_fold is stable) while exposing Residual is not, even though they both belong to try_trait_v2.
In this case, is it possible to rewrite the current implementation to only use Result/Option, stabilize it and revert back to a more general case when Residual trait gets stabilized?
I don't think it's possible to rewrite with Result/Option without changing the number or meaning of try_maps generic parameters in a way that won't be backward compatible with the revert.
Activity
a-lafrance commentedon Nov 12, 2021
Not sure if this change is still active, but I've stumbled upon a use case where a broader version of this for iterators in general, rather than strictly for arrays, would be useful. Is that something worth considering?
I'm totally new to both Rust contributions & open source in general, so I'm not sure if the idea of a general
try_mapis worth considering/pursuing, but I just thought I'd throw the idea out there since I thought it would be useful. Appreciate any feedback & insights!(And, if it gets to that point, I'd be interested in taking a stab at implementing it. Would love to make a contribution to Rust, no matter how small!)
scottmcm commentedon Dec 4, 2021
@arthurlafrance It'd suggest starting a conversation on
IRLOabout it. Or you can send a PR if it'd be easier to just write the code.This change is still open, but is for tracking this specific change, not a good place to discuss an additional possible API.
marcospb19 commentedon Aug 20, 2023
+1 for this one, it's the only way I found to run a fallible
.map()without collecting to aVec, and still useTryafterward, which leads to a concise and straightforward code.I guess that's what
iter.collect::<Result<_>>()and the unstableiter.try_collect()are intended for.SmnTin commentedon Aug 27, 2023
Is there anything blocking stabilization?
scottmcm commentedon Aug 28, 2023
Note that this, like
array::try_from_fnandIterator::try_findand similar, depends on theResidualtrait mechanism for mapping fromFoo<A>toFoo<[A; N]>, which is not used in any stable functions right now, so stabilization here is a bigger question than just the specific function in question.See #94119 (comment) where
array::from_fnwas accepted butarray::try_from_fnwasn't accepted due to this.tarcieri commentedon Aug 28, 2023
I believe #91285 is the tracking issue for stabilizing
Residualscottmcm commentedon Aug 28, 2023
Right, stabilizing
try_mapdoesn't require stabilizingResidualitself, but it does expose it, which is itself a commitment to have something like it forever.SmnTin commentedon Aug 29, 2023
Thank you for the replies! As far as I understood, there is a consensus that exposing
Trytrait in stable APIs is ok (e.g.Iterator::try_foldis stable) while exposingResidualis not, even though they both belong totry_trait_v2.SmnTin commentedon Aug 29, 2023
In this case, is it possible to rewrite the current implementation to only use
Result/Option, stabilize it and revert back to a more general case whenResidualtrait gets stabilized?eopb commentedon Sep 19, 2023
I don't think it's possible to rewrite with
Result/Optionwithout changing the number or meaning oftry_maps generic parameters in a way that won't be backward compatible with the revert.Rollup merge of rust-lang#118087 - GrigorenkoPV:refcell_try_map, r=Ma…
Rollup merge of rust-lang#118087 - GrigorenkoPV:refcell_try_map, r=Ma…
Rollup merge of rust-lang#118087 - GrigorenkoPV:refcell_try_map, r=Ma…
Rollup merge of rust-lang#118087 - GrigorenkoPV:refcell_try_map, r=Ma…
Unrolled build for #118087
Rollup merge of #118087 - GrigorenkoPV:refcell_try_map, r=Mark-Simula…
Rollup merge of rust-lang#118087 - GrigorenkoPV:refcell_try_map, r=Ma…
Rollup merge of #118087 - GrigorenkoPV:refcell_try_map, r=Mark-Simula…