This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-19
Channels
- # announcements (4)
- # aws (9)
- # babashka (1)
- # beginners (41)
- # cider (13)
- # clojure (45)
- # clojure-europe (16)
- # clojure-hungary (3)
- # clojure-norway (6)
- # clojure-uk (6)
- # clojurescript (14)
- # clr (3)
- # css (1)
- # datalevin (2)
- # datomic (2)
- # fulcro (8)
- # introduce-yourself (6)
- # jobs (3)
- # malli (2)
- # nbb (49)
- # off-topic (3)
- # reitit (23)
- # shadow-cljs (36)
- # tools-deps (2)
I tried to use nbb recently, but I think I am lacking some fundamentals, because I am stuck
all I need is to recursively read files from a directory on windows, filter and parse them 🙂
If I understand what you mean, you should be able to do something like this:
(require
'[babashka.fs :as fs]
'[clojure.string :as str])
(defn my-filter [path]
(str/starts-with? (fs/file-name %) "t"))
(defn my-parser [path]
(slurp (fs/file path))
(->> (fs/glob "somedir" "**")
(remove fs/directory?)
(filter my-filter)
(map my-parser)
looks like it, I was trying node interop and running into some Promise weirdness that I didn't understand
Yeah, I'd use the builtin Babashka and Clojure stuff first and see if I can avoid interop altogether.
If you know you only want files match a certain pattern, https://babashka.org/fs/codox/babashka.fs.html#var-glob can do a lot more than just return all of the files. You can do (fs/glob "somedir" "**.clj")
do get all of the Clojure files, for example.
agreed, for some reason I concluded that those wouldn't work, not sure why, I was too tired probably
trying this require form kills the nbb nrepl server with no value specified for babashka.fs
bb doesn't need anything installed. You can just download the static binary and use it.
That said, probably will try it, because your code looks simpler than anything I could do in node I think
I'm not a Node person myself, but I'm sure other people in the channel can get you over the current hurdle with nbb if that's preferable. 🙂
me neither, and the stuff I see should work, I just don't understand why I see a promise come out of another promise, when those should be unwrapped at once. Need more time to debug, but even better if I can avoid the whole mess
Promesa makes things a lot nicer: https://github.com/babashka/nbb#promesa
I switched for a bb repl but this require form still doesn't work, now it says lib names inside prefix lists must not contain periods
For Node.js you can use any Node library for globbing. E.g.: https://github.com/isaacs/node-glob
Added the glob example here: https://github.com/babashka/nbb/blob/main/examples/glob/example.cljs
I think I used the node based glob before and didn't have this feature? But will check again
awesome as always @U04V15CAJ
I was using the same code that @U054AT6KT typed in this thread at the very beginning. Could be that I messed up something else by not fully starting from scratch. But going back to nbb out of curiousity now:)