This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-01-30
Channels
- # announcements (2)
- # avi (12)
- # aws (6)
- # beginners (49)
- # boot (140)
- # cider (2)
- # cljs-dev (5)
- # cljsrn (9)
- # clojure (149)
- # clojure-czech (6)
- # clojure-miami (1)
- # clojure-nl (2)
- # clojure-russia (19)
- # clojure-ukraine (1)
- # clojurescript (34)
- # conf-proposals (36)
- # core-async (2)
- # cursive (11)
- # emacs (2)
- # funcool (23)
- # hoplon (2)
- # incanter (4)
- # jobs (1)
- # ldnclj (19)
- # om (47)
- # onyx (5)
- # proton (12)
- # re-frame (20)
- # ring-swagger (17)
- # testing (1)
Maybe I'm misunderstanding how to use applicatives, but here it goes.
I have something like (m/<$> validation-fn (m/ok value-to-validate))
and I want it to return (m/fail {:some #{:error}})
when validation-fn
fails and (m/ok validated-value)
- that is validation-fn
could change the constructor from ok
to fail
if the validation failed; but if I try to return m/ok
/ m/fail
from the validation-fn
m/<$>
just wraps that again resulting in #<Ok #<Ok ...>>
or #<Ok #<Fail ...>>
.
Is there anything that would make sense in such context or am I approaching it from a wrong angle?
My idea is to do be able to and
those validations so they can act on previous values; for example there would be integer?
which would validate whether the value is an integer and/or coercer it, so for (m/ok "12")
you'll get (m/ok 12)
(or (m/fail #{:not-integer})
when not an integer) and then you could pass it to, say between?
that would check whether the value fits in some range and either return (m/ok 12)
again or (m/fail #{[:not-between min max]})
.
Maybe I should just not try to string it like that, but create separate instances for each of validator and or
/ and
composition; I'll see if I can come up with something meaningful
but is wrong, you should create a bunch of "validation functions" that return ok, or fail
Yes, I'm doing something like right now and it works, but it has one downside, unless I'm missing something
Sure, we had plans in the past build a validation library basing on the cats applicative foundation, but we havent had enough time for it
so I don't know at this moment if the validation impl/approach is good enough for solve all cases
Yeah, possibly; I probably should have used bouncer or something, but thought this would be fun to try.
Basically my issue is I can do
((integer?) "12")
=> #<Ok #validators.core.ResultContainer{:v 12}>
((between? 10 14) 12)
=> #<Ok #validators.core.ResultContainer{:v 12}>
and it works, but I'm then not sure how to chain those two; so I can use between?
on the result of integer?
so they can both coerce and validate.