This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-29
Channels
- # announcements (4)
- # babashka (38)
- # beginners (66)
- # calva (35)
- # cider (3)
- # clj-on-windows (19)
- # cljs-dev (2)
- # clojure (29)
- # clojure-europe (15)
- # clojure-norway (2)
- # clojurescript (43)
- # clr (7)
- # community-development (6)
- # events (3)
- # hoplon (5)
- # lsp (23)
- # malli (7)
- # matrix (9)
- # nbb (53)
- # off-topic (5)
- # overtone (1)
- # practicalli (2)
- # re-frame (6)
- # reagent (17)
- # reitit (11)
- # specter (5)
- # tools-build (7)
- # xtdb (22)
Am I right that there is no analog to first
and last
in the stdlib Transducer reducing functions? Like:
(defn rfirst
"Grab the first item that makes it through the transduction."
([] nil)
([acc] acc)
([_ input] (reduced input)))
I'm not sure a last
transducer is particularly meaningful in the context of transducers :thinking_face:
Ah I see that that produces a transducer whereas the function I wrote above is a reducing function (called reducers elsewhere, but in Clojure that name seems to mean something else)
My intent was (transduce (filter pred) rfirst items)
For instance. And of course with comp
there can be many steps before or after that filtering.
Ah does any?
function like a reducer?
No. It's just the same as (constantly true)
which is what halt-when
needs to become produce a first transducer
ahhh I see, I had assumed it behaved like any
seen elsewhere
Tbh if you're writing the reducing function anyway, you may not need transducers. They just manipulate the reducing function after all.
For more complex transduction chains, first
can be handy, but there are other ways to achieve it depending on the scenario, as you've pointed out
Thanks! And if I need such an rfirst
I can always hand-write it quickly enough anyway
(defn regex-file-seq
"Lazily filter a directory based on a regex."
[re dir]
(filter #(re-find re (.getPath %)) (file-seq dir)))
(mapv
(fn [file] {:name (.getName file), :content (slurp file)})
(filter
(fn [file] (not (.isDirectory file)))
(regex-file-seq #".*\.clj" ( "/Users/bariscanates/prj/electric"))))
Hello! I have a question 🙂 The problem is this file seq brings all of json, js, map, md, clj, cljc and other types of files. I just need to filter them with absolute clj, cljc and edn. I tried to solve it with the "regex-file-seq" method but it still returns some other files types like ---> "/Users/bariscanates/prj/electric/.shadow-cljs/builds/dev/dev/ana/hyperfiddle/rcf/queue.cljs.cache.transit.json"] some other files. Where am I doing a mistake?#".*\.clj$"
The $
will anchor the match at the end of the string.
is there any chance that without using extra codes or fors to filter clj and cljc at the same time?
#".*\.(cljc?|edn)$"
.clj
, .cljc
, and .edn
You might find https://regex101.com/ helpful if you are just learning about regex.
He said "I just need to filter them with absolute clj, cljc and edn." in his original post so I assumed he wasn't interested in cljs flies...