I'm surprised no one went for condp
(defn parse-group [group-identifier line]
(condp = group-identifier
"ID1" (handle-id1 line)
"ID2" (handle-id2 line)
"ID3" (handle-id3 line)
(handle-unknown-id line)))
or something like that...
On Mon, May 21, 2012 at 11:59 AM, Timothy Baldridge <[email protected]>wrote:
> 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
> <[email protected]> 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 [email protected]
> > Note that posts from new members are moderated - please be patient with
> your
> > first post.
> > To unsubscribe from this group, send email to
> > [email protected]
> > 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 [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en