Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for array::try_map #79711

Open
2 of 4 tasks
eopb opened this issue Dec 4, 2020 · 10 comments
Open
2 of 4 tasks

Tracking issue for array::try_map #79711

eopb opened this issue Dec 4, 2020 · 10 comments
Labels
A-array Area: [T; N] C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@eopb
Copy link
Contributor

eopb commented Dec 4, 2020

Feature gate: #![feature(array_try_map)]

This is a tracking issue for

Public API

https://doc.rust-lang.org/nightly/std/primitive.array.html#method.try_map

impl<T, const N: usize> [T; N] {
    pub fn try_map<F, R>(
        self,
        f: F
    ) -> <<R as Try>::Residual as Residual<[<R as Try>::Output; N]>>::TryType
    where
        F: FnMut(T) -> R,
        R: Try,
        <R as Try>::Residual: Residual<[<R as Try>::Output; N]>;
}

Steps / History

Unresolved Questions

  • None yet.
@camelid camelid added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Dec 4, 2020
@eopb eopb mentioned this issue Dec 4, 2020
@KodrAus KodrAus added the Libs-Tracked Libs issues that are tracked on the team's project board. label Dec 16, 2020
@KodrAus KodrAus added the A-slice Area: [T] label Jan 6, 2021
@workingjubilee workingjubilee added A-array Area: [T; N] and removed A-slice Area: [T] labels Oct 6, 2021
@a-lafrance
Copy link
Contributor

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!)

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2021
Make `array::{try_from_fn, try_map}` and `Iterator::try_find` generic over `Try`

Fixes rust-lang#85115

This only updates unstable functions.

`array::try_map` didn't actually exist before; this adds it under the still-open tracking issue rust-lang#79711 from the old PR rust-lang#79713.

Tracking issue for the new trait: rust-lang#91285

This would also solve the return type question in for the proposed `Iterator::try_reduce` in rust-lang#87054
@scottmcm
Copy link
Member

scottmcm commented Dec 4, 2021

@arthurlafrance It'd suggest starting a conversation on IRLO about 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
Copy link
Contributor

marcospb19 commented Aug 20, 2023

+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.

@SmnTin
Copy link

SmnTin commented Aug 27, 2023

Is there anything blocking stabilization?

@scottmcm
Copy link
Member

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.

@tarcieri
Copy link
Contributor

I believe #91285 is the tracking issue for stabilizing Residual

@scottmcm
Copy link
Member

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.

@SmnTin
Copy link

SmnTin commented Aug 29, 2023

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.

@SmnTin
Copy link

SmnTin commented 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 when Residual trait gets stabilized?

@eopb
Copy link
Contributor Author

eopb commented Sep 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: [T; N] C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants