On Jun 15, 12:41 pm, Christian Schuhegger
wrote:
> Ah, sorry, perhaps I misunderstand you, but if you use multimethods
> (defmulti) in Clojure you do not need to "attach" methods to anything.
> The defmulti will allow you "dispatch-on-type" based on the key which
> is present in the map (e.g. if
Ah, sorry, perhaps I misunderstand you, but if you use multimethods
(defmulti) in Clojure you do not need to "attach" methods to anything.
The defmulti will allow you "dispatch-on-type" based on the key which
is present in the map (e.g. if :delete is present or if :insert is
present).
The nice th
On Jun 15, 11:51 am, Mark Engelberg wrote:
> On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips wrote:
> > Yes. I agree that can work, and that's what I've done in some other
> > situations, but it has the downside of lots of "recur" points
> > sprinkled around the loop body, which I think makes i
On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips wrote:
> Yes. I agree that can work, and that's what I've done in some other
> situations, but it has the downside of lots of "recur" points
> sprinkled around the loop body, which I think makes it almost as hard
> to reason about as having lots of
On Jun 14, 4:40 pm, Alex Osborne wrote:
> Matthew Phillips writes:
> > The only way I can think of to write it in Clojure is:
>
> > (reduce
> > (fn [items op]
> > (let [items1 (if (:delete op) (drop-index (:delete op) items)
> > items)]
> > (if (:insert op) (cons (:insert op) items1)
On Jun 14, 12:30 pm, Mark Engelberg wrote:
> On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips wrote:
> > List items = initialItems ();
>
> > for (Op op : operations)
> > {
> > if (op.requiresDelete ())
> > items.remove (op.indexToDelete ());
>
> > if (op.requiresAdd ())
> > items.add (op
On Jun 14, 12:05 pm, gaz jones wrote:
> if i was writing the java i would probably do a "tell dont ask"
> refactoring so that the operations had an applyTo method:
>
> List items = initialItems ();
>
> for (Op op : operations)
> {
> op.applyTo(items);
>
> }
>
> not sure what your op data structu
Matthew Phillips writes:
> The only way I can think of to write it in Clojure is:
>
> (reduce
> (fn [items op]
> (let [items1 (if (:delete op) (drop-index (:delete op) items)
> items)]
> (if (:insert op) (cons (:insert op) items1) items1)))
> items ops)
>
> i.e. I'm using a cascade
On 14 June 2011 12:37, Matthew Phillips wrote:
> The only way I can think of to write it in Clojure is:
>
> (reduce
> (fn [items op]
>(let [items1 (if (:delete op) (drop-index (:delete op) items)
> items)]
> (if (:insert op) (cons (:insert op) items1) items1)))
> items ops)
>
> i.e. I'
On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips wrote:
> List items = initialItems ();
>
> for (Op op : operations)
> {
> if (op.requiresDelete ())
> items.remove (op.indexToDelete ());
>
> if (op.requiresAdd ())
> items.add (op.indexToAdd (), op.newItem ());
> }
One way to transform th
if i was writing the java i would probably do a "tell dont ask"
refactoring so that the operations had an applyTo method:
List items = initialItems ();
for (Op op : operations)
{
op.applyTo(items);
}
not sure what your op data structure is, but i would image you could
translate that to the clo
11 matches
Mail list logo