Hi all,

I'm migrating an application from Java/Spring to Clojure and I'm searching 
for a good, functional approach. The app exposes a REST interface using 
compojure-api and primarily interacts with a relational database and sends 
email.

I think most people end up passing their database connection (and other 
stateful resources as required) around to non-pure functions that do the 
side-effectful work, while trying to push as much business logic into pure 
functions possible. My problem with this approach is that most of my app's 
functionality is in database interactions, so most of my functionality ends 
up being non-pure and difficult to test. For example, to unit test my 
functions it seems I'd have to mock my database connection.

Instead of this, I'm considering an approach where my functions instead 
return a data structure containing a description of the side-effects to be 
performed (e.g. "insert these rows into this table", "send this email", 
...), and having a single non-pure function that does all the 
side-effectful work described by the structure.

>From what I've read, it seems is sort of how Haskell does IO in a pure 
functional manner, using their IO monad.

Has anyone tried this sort of approach? Are there any libraries that might 
help? Any pitfalls I might be setting myself up for?

Thanks.

jk

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to