Well, though your DB is side-effects, your functions that write to it don't
have to be aware of that.  That's more a matter of dependency injection,
passing components around, and being careful to return a new object from
each operation.

Once you decouple your components from each other via some kind of abstract
interface (protocols are nice for this), it would be relatively easy to
create side-effect-free mock implementations for your tests or other use
cases.

So,
1. Create a suitable functional abstraction, where the side-effects are a
hidden implementation detail.
2. Be rigorous about using it.

We do this in our code via datomic, though we're not disciplined about
using a functional style with return-values from DB operations.  Injecting
the database as a dependency is enough to help testing use-cases and
overall code decoupling, and the implementation is all hidden behind a set
of protocols specific to our app.


On Thu, Oct 31, 2013 at 6:31 AM, Jozef Wagner <jozef.wag...@gmail.com>wrote:

> Following presentations may help
>
>  http://www.infoq.com/presentations/Clojure-Design-Patterns
> http://www.infoq.com/presentations/Thinking-in-Data
>
> JW
>
>
> On Thu, Oct 31, 2013 at 3:42 AM, Ben Brinckerhoff <
> bhbrinckerh...@gmail.com> wrote:
>
>> Clojure is the first functional programming language I've used for
>> anything more than toy examples, so I'm learning functional programming in
>> general as well as Clojure specifically. I understand the value of
>> creating pure functions in theory, but when writing applications, I'm
>> finding that logic and IO are getting hopelessly entangled.
>>
>> Specifically, in my web application, there is interaction with the DB on
>> most requests. The interaction may be quite complicated: e.g. first get
>> some user data, inspect it, and then make more DB calls if a user is
>> allowed to view some resource.
>>
>> Does anyone know of any books or articles on structuring functional code
>> to separate pure and impure functions? Or other resources? Projects that
>> are good examples?
>>
>> Although I've found good resources on writing pure functions and good
>> resources on using Clojure IO libraries, I haven't yet found anything that
>> talks about architectures that let you cleanly integrate the two in
>> real-world projects.
>>
>> Thanks,
>> Ben
>>
>> --
>> --
>> 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/groups/opt_out.
>>
>
>  --
> --
> 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/groups/opt_out.
>

-- 
-- 
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/groups/opt_out.

Reply via email to