Thank you for your input Stathis, I will have a look at them as well.

On Sunday, September 30, 2012 10:59:05 PM UTC+3, arekanderu wrote:
>
> Hello,
>
> I am trying to port an ugly piece of code from Ruby to clojure. So far I 
> have only ported it to clojure by keeping the same way it was written in 
> Ruby and i am trying to re-write it the clojure way because...well....its 
> very ugly.
> I have a complex hash map which it's structure is always the same and the 
> keys always known and by using the values in those keys, i make some 
> function calls with those values as parameters. You can find a simplified 
> version of the map and the function which steps into the map below.
>
> The map structure:
>
> (def my-map 
>>
>>   [{:a-key "foo" :items-a 
>>
>>   [{:another-key "bar" :items-b 
>>
>>   [{:items-c 
>>
>>     [{:name "bar-bar" :items-d 
>>
>>       [{:items-e 
>>
>>         [{:name "foo-foo"}]
>>
>>        }]
>>
>>      }]
>>
>>    }]
>>
>> }]
>>
>>   }])
>>
>>  
> And the function:
>
> (defn my-func []
>>
>>    (map (fn [a-hash]
>>
>>            (map (fn [item-a]
>>
>>                   (map (fn [item-b]
>>
>>                          (map (fn [item-c]
>>
>>                                 (when-not (empty? (:items-e item-c))
>>
>>                                   (map (fn [item]
>>
>>                                              (doSomething (:a-key item-a) 
>>> (:name item))
>>
>>                                           (:items-e items-c))
>>
>>                                  (doSomethingElse (:a-key item-a) 
>>> (:another-key item-b) (:name item-c))))
>>
>>                               (:items-c item-b)))
>>
>>                        (:items-b item-a)))
>>
>>                 (:items-a a-hash)))
>>
>>          my-map))) 
>>
>>
> I would really appreciate it if someone could propose an alternative way 
> of writing the above function or at least to point me where can I look for 
> some useful clojure functions that will help me do what I want but in a 
> cleaner way.
>
> Thank you for your time 
>  
>

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

Reply via email to