Re: Best way to work with an optional type

2014-11-25 Thread Cecil Westerhof
2014-11-25 18:30 GMT+01:00 David Pidcock : > 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

Re: Best way to work with an optional type

2014-11-25 Thread Cecil Westerhof
2014-11-25 14:31 GMT+01:00 Gary Verhaegen : > 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)

Re: Best way to work with an optional type

2014-11-25 Thread David Pidcock
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 you

Re: Best way to work with an optional type

2014-11-25 Thread Timothy Baldridge
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 de

Re: Best way to work with an optional type

2014-11-25 Thread Fluid Dynamics
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-percenta

Re: Best way to work with an optional type

2014-11-25 Thread Gary Verhaegen
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 :l

Best way to work with an optional type

2014-11-25 Thread Cecil Westerhof
I started playing with Clojure again. I made the following three functions: (defn get-percentage [place total-count] (int (Math/round (double (/ (* place 100) total-count) (defn get-percentage-low [place total-count] (int (Math/floor (/ (* place 100) total-count (d