Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p/all returns js array #43

Closed
zrzka opened this issue Feb 22, 2017 · 2 comments
Closed

p/all returns js array #43

zrzka opened this issue Feb 22, 2017 · 2 comments

Comments

@zrzka
Copy link

zrzka commented Feb 22, 2017

Is there a reson why (p/all ...) returns js array instead of cljs sequence? Is this a bug in 1.8.0 or desired behavior?

Some examples

Not working

(defn question-sets
  [creds env org-id]
  (->> (p/all [(enabled-question-set-items creds env "*")
               (enabled-question-set-items creds env org-id)])
       ;(p/map js->clj)
       (p/map flatten)
       (p/map #(-> {:question-sets %}))))

Working

(defn question-sets
  [creds env org-id]
  (->> (p/all [(enabled-question-set-items creds env "*")
               (enabled-question-set-items creds env org-id)])
       (p/map js->clj)
       (p/map flatten)
       (p/map #(-> {:question-sets %}))))

Working

(defn question-sets
  [creds env org-id]
  (->> (p/all [(enabled-question-set-items creds env "*")
               (enabled-question-set-items creds env org-id)])
       (p/map (fn [[qs1 qs2]]
                (into [] (concat qs1 qs2))))
       (p/map #(-> {:question-sets %}))))

Type outputs

(defn question-sets
  [creds env org-id]
  (->> (p/all [(enabled-question-set-items creds env "*")
               (enabled-question-set-items creds env org-id)])
       (p/map #(do (println "array?" (array? %))
                   (-> %)))
       (p/map (fn [[qs1 qs2]]
                (do
                  (println "qs1.array?" (array? qs1))
                  (println "qs2.array?" (array? qs2))
                  (into [] (concat qs1 qs2)))))
       (p/map #(do (println "array?" (array? %))
                   (-> %)))
       (p/map #(-> {:question-sets %}))))

->

array? true
qs1.array? false
qs2.array? false
array? false
@niwinz
Copy link
Member

niwinz commented Feb 22, 2017

It is expected behavior. As js arrays can be destructured in the same way as clojurescript data structures, and converting that array constantly to a vector has some performance penalities. So, for avoid unnecesary data conversion, the raw value is emitted.

If you explicitly need a vector just do (p/map vec promise).

@niwinz niwinz closed this as completed Feb 22, 2017
@zrzka
Copy link
Author

zrzka commented Feb 23, 2017

Okay, thanks for the explanation. Was expecting something like this, but wasn't sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants