babashka / sci.configs

A collection of ready to be used SCI configs
https://babashka.org/sci.configs/
Other
20 stars 18 forks source link

Support promesa/map and promesa/mapcat ops #4

Closed jaidetree closed 2 years ago

jaidetree commented 2 years ago

Found myself needing this when implementing a recursive readdir function with fs/promises.readdir.

Was able to work around it but p/mapcat would be cleaner I feel:

(defn readdir
  [dirpath]
  (p/->> (fs/readdir dirpath #js {:withFileTypes true})
         (map (fn [dirent]
                (let [filepath (.join path dirpath (.-name dirent))]
                  (cond (.isDirectory dirent)
                        (readdir filepath)

                        (.isFile dirent)
                        [filepath]

                        :else
                        []))
                ))
         (p/all)
         (reduce #(into %1 %2) [])))