Adds FuncMut and PolyMut, which parallel Func and Poly.#137
Adds FuncMut and PolyMut, which parallel Func and Poly.#137remexre wants to merge 2 commits intolloydmeta:masterfrom
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:
|
ExpHP
left a comment
There was a problem hiding this comment.
Looks good to me, could just use some examples/tests.
| where | ||
| Tail: HFoldLeftable<F, Acc>, | ||
| F: Fn(Acc, H) -> Acc, | ||
| F: FnMut(Acc, H) -> Acc, |
| impl<F, R, H, Tail> HMappable<F> for HCons<H, Tail> | ||
| where | ||
| F: Fn(H) -> R, | ||
| F: FnMut(H) -> R, |
| /// ``` | ||
| /// # #[macro_use] | ||
| /// # extern crate frunk; | ||
| /// # use frunk::{FuncMut, PolyMut}; |
There was a problem hiding this comment.
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.
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.
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>acceptFnMutinstead of justFn; I don't believe this would be breaking, but I can split it out if it is.