On Mon, Jun 13, 2011 at 7:37 PM, Matthew Phillips <[email protected]> wrote:
> List<Item> 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 this is loop-recur.
(loop [items initialitems, ops (seq operations)]
  (if-not ops items
    (let [op (first ops)]
        ;; Now you can write the logic pretty much the way you did in java
        (cond
             (.requiresDelete op)  (recur (.remove items (.op
indexToDelete)) (next ops))
             (.requiresAdd op) (recur (.add items (.op indexToAdd)
(.op newItem)) (next ops)))))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to