The way yada uses Records (and maybe all uses of Records) seems magical to me. When calling a response fn, it wraps the ctx
in a Response
record, and if you merge the correct way (or assoc), you get to control status code, etc. If you donโt merge the correct way, you get a hashmap as the body.
Is this idiomatic Clojure?
It's a tradeoff. The problem in Liberator was in determining if the user was returning a map or actually a Ring response. Namespaced keys might be a better approach.
I agree, the approach in yada isn't idiomatic
But records are useful
They have Rich's seal of approval ๐
@grav what's the incorrect way to merge?
(defrecord Foo [])
(instance? Foo (merge (Foo.) {})) ;; => true
(instance? Foo (merge {} (Foo.))) ;; => false
@malcolmsparks Haha, yes they have. Since 1.2 as I read it. Maybe heโs changed his mind since then ๐
But I certainly see the dilemma wrt map vs Ring response