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

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

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

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

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

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