-
Notifications
You must be signed in to change notification settings - Fork 58
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
Adds FuncMut and PolyMut, which parallel Func and Poly. #137
base: master
Are you sure you want to change the base?
Conversation
I definitely agree with taking the most general For The current choice of Now, your PR actually seems to have a neat solution to this that I'm not sure if we've tried or discussed before, which is that one can use different newtype wrappers |
I'm using this so I can call a trait method on an HList of values that all belong to the same trait. The specific code is here: There's not really a huge reason to have |
|
The question of consistency is currently a null point; Func takes no context, so Furthermore, @remexre's use case is a generic closure, which is even more monumentally difficult to make a comfortable interface around. It's only one step away from the most complicated example I have in my own experimental repo unbox!{
// Define a generic context
pub struct Contains<'a, T>(&'a [T]) where T: 'a;
// Make it a generic closure
impl Fn <'b, U: 'b>(&self, u: &'b U) -> bool
where T: PartialEq<U>,
{ self.0.iter().any(|t| t == u) }
} (remexre's example is almost as complicated, but with a monomorphic context) Honestly, in my own projects, I just write my own traits now for mapping over hlists in particular ways with certain types of context, since there's no generic solution I've found comfortable to use. |
Here are my recent thoughts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, could just use some examples/tests.
@@ -1143,11 +1158,11 @@ where | |||
impl<F, H, Tail, Acc> HFoldLeftable<F, Acc> for HCons<H, Tail> | |||
where | |||
Tail: HFoldLeftable<F, Acc>, | |||
F: Fn(Acc, H) -> Acc, | |||
F: FnMut(Acc, H) -> Acc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for this
@@ -943,12 +958,12 @@ impl<F> HMappable<F> for HNil { | |||
|
|||
impl<F, R, H, Tail> HMappable<F> for HCons<H, Tail> | |||
where | |||
F: Fn(H) -> R, | |||
F: FnMut(H) -> R, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for this
/// ``` | ||
/// # #[macro_use] | ||
/// # extern crate frunk; | ||
/// # use frunk::{FuncMut, PolyMut}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because some items are exported under multiple paths, I've been making it a point for doc examples to always show the intended paths for using stuff from frunk
, so unhide this.
Likewise for the #[macro_use] extern crate
/// } | ||
/// } | ||
/// | ||
/// fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hide the fn main() {
.
There's some examples of how I would format an example like this in
https://github.com/lloydmeta/frunk/blob/master/src/validated.rs
/// fn main() { | ||
/// let mut string = String::new(); | ||
/// | ||
/// { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really can't wait for NLL...
I haven’t taken a thorough look (currently on vacation with spotty internet) but the proposed changes and feedback look reasonable to me :) Also 👍 for |
This has been sitting here for a while, should I just push the big green button? |
I need to add examples+tests still; it's finals week here so I'm gonna be a bit busy until the 19th or 20th; I should be able to do them then, though. |
This also makes
HMappable<F>
acceptFnMut
instead of justFn
; I don't believe this would be breaking, but I can split it out if it is.