GithubHelp home page GithubHelp logo

And Then or Flat Map function about combine HOT 6 CLOSED

marwes avatar marwes commented on June 22, 2024
And Then or Flat Map function

from combine.

Comments (6)

hawkw avatar hawkw commented on June 22, 2024

I might just go ahead and fork the repo and implement it myself, if I have the time.

from combine.

Marwes avatar Marwes commented on June 22, 2024

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 then return a result instead of a parser.

from combine.

hawkw avatar hawkw commented on June 22, 2024

There is the function then already.

Yeah, I did see the then function, but I was not really sure if it could be used for this purpose since it returns a parser.

The use case I have in mind here is parsing some strings that represent numbers, and then turning them into numeric values using from_str(), which returns a Result. It would be great if instead of

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 unwrap(), and have the error result from either from_str_radix or from_u32 carried over as a parse error.

Just my two cents. I know I would definitely find this pattern useful.

from combine.

Marwes avatar Marwes commented on June 22, 2024

One problem with your proposed function is that it needs a FromError implementation for ParseError. Nothing that isn't solvable but I though I should point it out. As ParseError is currently it would probably mean converting the error to a string and using Message variant though I would be open for suggestions for a better handling of user created errors.

from combine.

hawkw avatar hawkw commented on June 22, 2024

Ah, true, I hadn't thought of that. Well, put this one on the back burner for if/when you have time, I suppose.

from combine.

Marwes avatar Marwes commented on June 22, 2024

Closed through #28.

from combine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.