In this case I prefer either:

  (cond (= group-identifier "ID1")
            (handle-id1 line)
          (= group-identifier "ID2")
           (handle-id2 line)
          (= group-identifier "ID3")
            (handle-id3 line))

Or just use core.match:

(match [group-identifier]
           ["ID1"]  (handle-id1 line)
           ["ID2"]  (handle-id1 line)
           ["ID3"]  (handle-id1 line))

But then again, I have this "thing" for pattern matching...it's so elegant.

Timothy Baldridge

On Mon, May 21, 2012 at 10:54 AM, Christian Guimaraes
<cguimaraes...@gmail.com> wrote:
> Hi all,
>
> I'm struggling with "when" code structures and my imperative mindset.
>
> What is the better approach (or functional approach) to work with a code
> like the below?
>
> (defn parse-group [group-identifier line]
>   (when (= group-identifier "ID1")
>     (handle-id1 line))
>   (when (= group-identifier "ID2")
>     (handle-id2 line))
>   (when (= group-identifier "ID3")
>     (handle-id3 line)))
>
> Thank you.
> -- christian
>
>
> --
> 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



-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

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