Fork me on GitHub
#clojure-uk
<
2019-12-29
>
dharrigan07:12:11

Good Morning Everyone! 🙂

dharrigan10:12:38

So, say you have a db connection and a function that uses that dB connection, would it be better to pass in that connection as a function argument and use it, or pass that db connection in, but return a function that can be used (e.g., to perform a select), in effect wrapping the db connection?

dharrigan10:12:19

E.g., (defn [conn sql] (select conn sql....)) Versus (defn [conn] (fn[SQL] select conn SQL...)))

dominicm11:12:12

I would avoid wrapping. Clojure has tools for this, eg partial

dominicm12:12:30

There's exceptions to this, for example where you're defining a standard library of particular calling convention (eg transducers)

dharrigan12:12:26

so, better to pass it in and use it directly, rather than returning a function that wraps. Okaydokey. Let me have a play with that in my code. Thanks! 🙂

flefik19:12:12

the former is also much easier for you to test (for some definitions of much)