Hi,
I think that multimethods will fit better in my case, since I have more
than three ID's to handle.
Thank you all for the answers.
-- christian.
On Mon, May 21, 2012 at 5:04 PM, Timothy Baldridge wrote:
> > A multimethod might also be an appropriate way forward for you.
>
> +1 For multimeth
> A multimethod might also be an appropriate way forward for you.
+1 For multimethods, don't hardcode it if you don'tt have to.
Timothy
--
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
Not
or simply use `case`
(case group-identifier
"ID1" (handle-id1 line)
"ID2" (handle-id2 line)
"ID3" (handle-id3 line))
2012/5/21 Timothy Baldridge
> In this case I prefer either:
>
> (cond (= group-identifier "ID1")
>(handle-id1 line)
> (= group-identifier "ID2")
On Monday, May 21, 2012 6:54:28 PM UTC+3, Christian Guimaraes 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]
On Mon, May 21, 2012 at 8:54 AM, Christian Guimaraes
wrote:
> What is the better approach (or functional approach) to work with a code
> like the below?
A simple translation to condp:
(defn parse-group [group-identifier line]
(condp = group-identifier
"ID1" (handle-id1 line)
"ID2" (han
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 Baldri
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"
On May 21, 2012, at 10:54 AM, Christian Guimaraes wrote:
> 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?
I think you're looking for cond (from memory, syntax might be wrong):
(
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 "