On 14 June 2011 12:37, Matthew Phillips mattp...@gmail.com 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)
Matthew Phillips mattp...@gmail.com 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
On Jun 14, 12:05 pm, gaz jones gareth.e.jo...@gmail.com wrote:
if i was writing the java i would probably do a tell dont ask
refactoring so that the operations had an applyTo method:
ListItem items = initialItems ();
for (Op op : operations)
{
op.applyTo(items);
}
not sure what your
On Jun 14, 12:30 pm, Mark Engelberg mark.engelb...@gmail.com wrote:
On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips mattp...@gmail.com wrote:
ListItem items = initialItems ();
for (Op op : operations)
{
if (op.requiresDelete ())
items.remove (op.indexToDelete ());
if
On Jun 14, 4:40 pm, Alex Osborne a...@meshy.org wrote:
Matthew Phillips mattp...@gmail.com 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
On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips mattp...@gmail.com 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
On Jun 15, 11:51 am, Mark Engelberg mark.engelb...@gmail.com wrote:
On Tue, Jun 14, 2011 at 7:41 PM, Matthew Phillips mattp...@gmail.com 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
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 thing
On Jun 15, 12:41 pm, Christian Schuhegger
christian.schuheg...@gmail.com 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
if i was writing the java i would probably do a tell dont ask
refactoring so that the operations had an applyTo method:
ListItem 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
On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips mattp...@gmail.com wrote:
ListItem 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
11 matches
Mail list logo