Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage :normal place total-count))
([mode place total-count]
(condp = mode
On Tuesday, November 25, 2014 8:32:14 AM UTC-5, Gary Verhaegen wrote:
Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage
Also, you can use multi-methods:
(defmulti get-percentage (fn [x mode] mode))
(defmethod get-percentage :default
[x _]
(get-percentage x :high))
(defmethod get-percentage :high
[x _]
...)
(defmethod get-percentage :low
[x _]
...)
This has the advantage to not only having a clear
While I think the latter two solutions show off Clojures ease of extensibility,
I personally believe the first technique is more appropriate for the current
wxample.
I mean, how many different ways of calculating and rounding a percentage are
there?
--
You received this message because
2014-11-25 14:31 GMT+01:00 Gary Verhaegen gary.verhae...@gmail.com:
Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage :normal
2014-11-25 18:30 GMT+01:00 David Pidcock eraz0rh...@gmail.com:
While I think the latter two solutions show off Clojures ease of
extensibility, I personally believe the first technique is more appropriate
for the current wxample.
I mean, how many different ways of calculating and rounding a