Fork me on GitHub
#clojure-spec
<
2017-08-27
>
hmaurer17:08:24

Hi! Is there a way to get only the keys specified in a spec (req and opt) and nothing else after validating a map? And to do so with nested maps too?

hmaurer17:08:53

I expected conform to do this but it doesn't appear to

hmaurer21:08:16

the spec-tools package seems to offer a solution to my problem

ikitommi18:08:27

Hi. The s/conformer seems to take the optional unf function as a second argument for unforming. It defaults to nil currently. Would an identity be a better default?

ikitommi18:08:36

e.g. this would not fail by default:

Alex Miller (Clojure team)00:08:35

yes, it would still fail by giving you the wrong result

Alex Miller (Clojure team)00:08:18

given that conformers are used to transform the input, using identity is virtually always as wrong as nil. much better to fail and tell you how to fix imo

ikitommi18:08:46

(require '[clojure.spec.alpha :as s])

(s/def ::spec (s/conformer str))

(s/conform ::spec 1)
; => "1"

(s/unform ::spec (s/conform ::spec 1))
; CompilerException java.lang.IllegalStateException: no unform fn for conformer

hmaurer21:08:13

Anybody familiar with spec-tools here?

ikitommi07:08:19

@U5ZAJ15P0 I am, one of developers of the lib.

hmaurer19:08:41

@U055NJ5CC Hi! I wanted to ask if there is a utility function to walk a (deeply nested) map together with its associated spec

hmaurer19:08:56

I just realised it’s precisely what has been discussed here https://github.com/metosin/spec-tools/issues/65

hmaurer19:08:03

does such a function exist now?

ikitommi05:08:46

@U5ZAJ15P0 Not yet. Just commented on the issue. If you have ideas, please share them on the issue. Contributions welcome too