In MVC pattern, Model should take responsibility for business logic.
Therefore I write validate function for creating in the model.
If creating a instance of the model should be safe, I must validate a
parameter in the create function.
My problem is that a controller have to validate a parameter twice in
the validate function and the create function.

Ring handler example

(defn handler [{:keys [params] :as req}]
  (if (person/valid? params)
    {:status 200 :body (json/generate-string (person/create params))}
    {:status 400}))

I think this might be suited to monads, which I don't fully
understand.

On Jan 4, 4:35 am, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> Some of the most common uses for monads have pre-existing mechanisms
> with Clojure to handle them, e.g.:
> sequence monad (for)
> state monad (Clojure has many stateful mechansisms)
> maybe monad (Clojure programmers usually just return nil for failure,
> and use something like when-let to process it)
>
> In terms of higher-level DSLs constructed out of monads, the most
> useful monadic frameworks I've seen are monads for parsing, and monads
> for representing probability distributions.  If I needed to do one of
> those things in Clojure, I'd look closely at monad options.  But since
> I haven't needed to do those things, and the common uses for monads
> are already covered, I haven't found a need to do any monadic style
> programming in my own code.
>
> --Mark

-- 
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

Reply via email to