Giter Club home page Giter Club logo

Comments (9)

wilkerlucio avatar wilkerlucio commented on July 28, 2024

Nothing by default, but it seems easy to create one, do you need anything more than what this example function is providing?

from spec-coerce.

DogLooksGood avatar DogLooksGood commented on July 28, 2024

nothing more i think. i'm just confused with the current coerce behavior, why there's no error or return a result represent invalid when the data can't be coerce? in this case, after coerce i still don't know if the data is valid or not.

the example function will walk the structure twice.

from spec-coerce.

carocad avatar carocad commented on July 28, 2024

I agree with @DogLooksGood. The current behavior of Clojure spec is to return ::invalid on a failed conform.

Considering that conform and conformers are the current (thought incorrect) way of handling coercion I think this would be an expected behavior.

from spec-coerce.

wilkerlucio avatar wilkerlucio commented on July 28, 2024

@carocad
The idea to keep things is just to don't break the structure itself, the coerce method is for a single item coercion, this API I don't think on changing, but I can provide a new one like coerce! that throws an error when the coercion fails, what you think?

from spec-coerce.

carocad avatar carocad commented on July 28, 2024

I think that having a bit more room to play would be better. In Clojure we have conform, valid?, assert.

  • valid? in this case is similar to coerce. I.e always return a value

  • I think assert would be perfect for the case where I would like to stop the flow of a program if the input is invalid, like in web servers.

  • however I think there is also a need for something like conform behavior where the result would be ::invalid not an exception. The use case of this is data processing and filtering. If I have thousands of lines to coerce and only one of them is invalid I would not like my program to break because of it. I would prefer either to filter it manually or to just log it and continue; both of which are not very appealing to do with a try catch.

Hope it helps

from spec-coerce.

wilkerlucio avatar wilkerlucio commented on July 28, 2024

@carocad @DogLooksGood

Hello guys, I was thinking about it, I have this idea for the fns, would like your input on that:

  • sc/coerce - will keep working as is, returns original value
  • sc/coerce! - throws exception when coercion fails
  • sc/conform - returns value coerced and conformed, returning ::s/invalid as the conform does when doesn't work

And question, how are you using it? Are you hitting sc/coerce directly using map specs or other things, or using the coerce-structure for maps?

from spec-coerce.

DogLooksGood avatar DogLooksGood commented on July 28, 2024

I would use it for apis, so i care about both validation and type transform.

I think it's not good to have a function named conform, then people have s/conform and sc/conform. from the viewpoint of a user like me, i think it's kind of messy.

from spec-coerce.

carocad avatar carocad commented on July 28, 2024

I think that API is fine. Although I understand the point of dog looks good, I am not able to come up with a more appropriate name.

I think that namespaces are meant to precisely cover the case of functions having the same name.

And question, how are you using it?

I'm using coerce directly with map Spec. To be honest I didn't understand why there was a second function for coercion :)

from spec-coerce.

wilkerlucio avatar wilkerlucio commented on July 28, 2024

Just released on 1.0.0-alpha7

from spec-coerce.

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.