Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Transforming an ugly nested loop into clojure code
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
gaz jones  
View profile  
 More options Oct 1 2012, 6:22 pm
From: gaz jones <gareth.e.jo...@gmail.com>
Date: Mon, 1 Oct 2012 17:22:18 -0500
Local: Mon, Oct 1 2012 6:22 pm
Subject: Re: Transforming an ugly nested loop into clojure code
You appear to be running over the map purely for side-effects,
therefore off the top of my head something like:

(defn my-func
  [data]
  (doseq [area data
          warehouse (:warehouses area)
          container (:containers warehouse)
          box (:boxes container)]
    (if-not (empty? (:items box))
      (doseq [item (:items box)] (do-something (:box box) (:item item)))
      (do-something-else (:warehouse warehouse)
                         (:container container)
                         (:box box)))))

Might be more appropriate...

On Mon, Oct 1, 2012 at 5:07 PM, arekanderu <arekand...@gmail.com> wrote:
>> (def my-data [{:area "Somewhere" :warehouses

>>                [{:warehouse "W54321" :containers

>>                 [{:container "C12345" :boxes

>>                   [{:box "B12345" :items

>>                     [{:item "I12345"}]}]}]}]}

>>               {:area "SomewhereElse" :warehouses

>>                [{:warehouse "W54321" :containers

>>                 [{:container "C54321" :boxes

>>                   [{:box "B54321" :items

>>                     [{:item "I54321"}]}]}]}]}])

>> (defn my-func [data]

>>   (map (fn [area]

>>          (map (fn [warehouse]

>>                 (map (fn [container]

>>                        (map (fn [box]

>>                               (if (not (empty? (:items box)))

>>                                 (map (fn [item]

>>                                        (doSomething (:box box) (:item
>> item)))

>>                                      (:items box))

>>                                 (doSomethingElse (:warehouse warehouse)
>> (:container container) (:box box))))

>>                               (:boxes container)))

>>                      (:containers warehouse)))

>>               (:warehouses area)))

>>        data))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.