Comments (9)
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.
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.
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.
@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.
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.
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 valuesc/coerce!
- throws exception when coercion failssc/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.
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.
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.
Just released on 1.0.0-alpha7
from spec-coerce.
Related Issues (20)
- inst? coerce seems very strict HOT 13
- Setup CLJS test with shadow + karma
- coerce! attempts to call s/valid? on unqualified keywords HOT 4
- Coercion for Decimal doesn't work as expected HOT 2
- Coercion to string has no effect HOT 3
- Throws error for a spec with an `or` form in the `:req-un` set of a `keys` form. HOT 2
- Bad coercions for pos/neg/nat specs HOT 4
- Coercing a sequence changes its order HOT 2
- Nilables don't work when specs are used
- parse-long and parse-double should cast numeric types
- Support for multi-specs? HOT 1
- `spec/and` precludes coercion HOT 3
- First class coercion contexts HOT 2
- add support for s/merge HOT 2
- coerce-structure overrides nested unqualified keys support
- 1.0.0-alpha15 doesn't compile in CLJS HOT 1
- Regex cat spec doesn't seem to be coerced at all HOT 3
- Behavior for specs defined as set literals HOT 3
- Coerce doesn't work in cljs HOT 6
- Is support for s/nilable on the roadmap? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spec-coerce.