-
Notifications
You must be signed in to change notification settings - Fork 95
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
And Then or Flat Map function #22
Comments
I might just go ahead and fork the repo and implement it myself, if I have the time. |
There is the function then already. I would not be opposed to having both though if you think its useful. Maybe the current function should just be replaced with the one you proposed. Looking through my code the only time I use it I could just as well have |
Yeah, I did see the The use case I have in mind here is parsing some strings that represent numbers, and then turning them into numeric values using many1(hex_digit())
.map(|x| char::from_u32(u32::from_str_radix(x, 16).unwrap()).unwrap()) I could just say many1(hex_digit())
.and_then(|x| u32::from_str_radix(x,16))
.and_then(|x| char::from_u32(x)) This way, I could avoid using Just my two cents. I know I would definitely find this pattern useful. |
One problem with your proposed function is that it needs a |
Ah, true, I hadn't thought of that. Well, put this one on the back burner for if/when you have time, I suppose. |
Closed through #28. |
Here's a feature request for something I think would be useful.
The
map
function can be used to apply a function to the successful result of a parser. I propose the addition of an additional function which applies a function returningResult
to the successful result of a parser. If that function returned an error, the error value would be carried over as theParseResult
's error value, otherwise, it carries over the new success value.I'm not quite sure what the idiomatic Rust name for this would be. In Scala, which I'm more familiar with, this is referred to as
flatMap
, while Rust'sResult
type calls itand_then
. Whatever it's called, I think this would be a pretty useful feature.The text was updated successfully, but these errors were encountered: