-
Notifications
You must be signed in to change notification settings - Fork 60
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
Feat: Conditionally applied methods #99
Comments
It would require a new trait in this crate which I would not qualify as "minor change" but I would definitely like to use this myself. Alternatively or additionally to this, I've thought of an PS: I see this repo has been moved to rayon-rs recently, congrats. |
Add: + Trait `ApplyEither` - `apply_either`: Conditionally choose a function and apply it. - `apply_if`: Conditionally choose to apply a function. + Impl `ApplyEither` for generic type `T`, where `T` is `Sized` Close Feat: Conditionally chained methods rayon-rs#99
Add: + Trait `ApplyEither` - `apply_either`: Conditionally choose a function and apply it. - `apply_if`: Conditionally choose to apply a function. + Impl `ApplyEither` for generic type `T`, where `T` is `Sized` Close Feat: Conditionally chained methods rayon-rs#99
Wrote a rough implementation for the feature (keeping @Philippe-Cholet's suggestion for an Accepting this feature request (followed by me drafting a PR and getting the code reviewed) is the only delay now. 😆 |
Hi @cuviper (I apologize for the ping. I pinged you because you were the most active contributor), I just wanted to know if this feature request will be accepted (since this issue and my branch are starting to go stale). I have an implementation on my fork, ready to be reviewed and merged. |
I think I would prefer just the |
I thought having simple functions like some_foo
.into_left()
.some_bar()
.some_baz() over Either::Left(some_foo)
.some_bar()
.some_baz() And also lets you use it anywhere in the middle of a method chain. Like: some_foo
.some_bar()
.into_left()
.some_baz() Just my two cents.
Well in that case I will get started on implementing an In all seriousness, depending on the final decision, I will probably make a tiny crate that provides this functionality using |
Another issue I have with A closure version of fn into_either_with(self, f: impl FnOnce(&Self) -> bool) -> Either<Self, Self>;
Sure, you're free to do so, of course. That's especially useful when there are potential design choices that aren't clear yet, so you'll be able to make breaking changes independently of |
@SFM61319 Do you make a PR for |
@Philippe-Cholet I will make one now. |
Add: + Trait `IntoEither` - `into_either`: Conditionally convert any sized type into any variant of `Either`. - `into_either_with`: Like `into_either`, but takes a predicate function instead. + Impl `IntoEither` for generic type `T`, where `T` is `Sized` Close rayon-rs#99
@Philippe-Cholet by the way, I made a crate named |
Add: + Trait `IntoEither` - `into_either`: Conditionally convert any sized type into any variant of `Either`. - `into_either_with`: Like `into_either`, but takes a predicate function instead. + Impl `IntoEither` for generic type `T`, where `T` is `Sized` Close rayon-rs#99
Coming from rust-itertools/itertools#881 - methods that let you apply other methods conditionally would be helpful.
Something that lets you do:
Along with other methods for ternary conditions, etc., like:
While these examples revolve around iterators, the scope itself of these conditionally applied methods is much larger and in my humble opinion very useful.
It's simple to implement and could be very useful, especially when you have a large method chain and breaking it up for an if[-else] block would negatively affect the readability (see my doc examples).
I have already written a simple implementation on my local fork of
either
. Correct me if I'm wrong, but this only needs minor changes to work with theeither
crate instead.If this feature request gets accepted, I would love to contribute to it myself.
The text was updated successfully, but these errors were encountered: