murtaza52
murtaza52

Reputation: 47431

better idiom for the following flow

I have a piece of code as follows -

        (future
          (
            (comp
             (fn [data]
               (service/parse srv data))
             (fn []
               (service/fetch srv))
            )))

Basically there are two functions fetch and parse which I have to call in a future. The result of the fetch is used by the parse function. Somehow the above seems to verbose, as I have to create anonymous functions just so that I can comp them and then use an extra () to execute the comped function.

Any better ways of achieving the above ?

Upvotes: 0

Views: 55

Answers (2)

Ankur
Ankur

Reputation: 33657

(future
    (->> (service/fetch srv)
         (service/parse srv)))

Upvotes: 2

Michiel Borkent
Michiel Borkent

Reputation: 34840

I assume srv is some url or other object defined in a Var? Unclear from your code. Anyway, the equivalent:

(future
  (let [data (service/fetch srv)]
    (service/parse srv data)))

or simply

(future
  (service/parse srv (service/fetch srv)))

I expect you can refactor parse so it doesn't depend on srv, but I don't have enough info about your problem to be sure.

Upvotes: 2

Related Questions