This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-21
Channels
- # bangalore-clj (11)
- # beginners (82)
- # boot (1)
- # braveandtrue (29)
- # cider (16)
- # cljdoc (2)
- # cljs-dev (2)
- # clojure (74)
- # clojure-dev (3)
- # clojure-italy (2)
- # clojure-mke (1)
- # clojure-nl (4)
- # clojure-sg (1)
- # clojure-spec (1)
- # clojure-uk (53)
- # clojure-ukraine (1)
- # clojurescript (33)
- # cursive (29)
- # datomic (59)
- # editors (4)
- # emacs (14)
- # fulcro (2)
- # graphql (12)
- # hoplon (2)
- # nyc (4)
- # onyx (5)
- # parinfer (10)
- # pedestal (22)
- # re-frame (11)
- # reagent (35)
- # ring-swagger (5)
- # shadow-cljs (150)
- # tools-deps (9)
- # vim (1)
- # yada (20)
Does anyone here use Windows for clojure dev?
@danial.javady check out this clojureverse thread
Is this an OK way to use line-seq
? (with-open [rdr (io/reader (io/file "my-file.txt"))] (line-seq rdr))
It had been working but stopped with one particular file. If I wrap the line-seq
call in doall
it works again, but obviously that defeats the point of me using it.
Error I get is IOException Stream closed java.io.BufferedReader.ensureOpen (BufferedReader.java:122)
Line seq returns a lazy collection. In effect just a function that can be invoked to realize more elements. The problem is that it will be involved after the resource has been closed
@dpsutton thanks!
So if I have a function that accepts a file and I want to return a lazy seq of some operations over that files lines would it be better to make that function instead accept a reader and let the caller handle closing the file?
It's a problem you'll face. But if you want lazy sequence then you need to deal with the delayed using of the resource
Ok, thanks. It sounds like this pattern might not be as common as I imagined it would be.
If you Google it sean has a nice solution on stack overflow. There's also a deprecated lib linked in it https://github.com/clojure/clojure-contrib/blob/aa3f018f65006c78b08703e7adef04b7f39e1542/src/main/clojure/clojure/contrib/duck_streams.clj#L236
This looks fine to me as long as you make sure to always consume the entire sequence. Otherwise you could run out of file descriptors
Ah ok, interesting. read-lines
is definitely more of what I had in mind. Thanks, I'll do a bit more research on it.
@danial.javady On multiple occasions I have seen @seancorfield mention that he likes using WSL on Windows for Clojure dev (and probably other purposes)
Hey I'm doing something like (comp vec set merge)
to update a vector but remove duplicates if the merge introduces one
An issue here is that merge doesn't error on a vector, but isn't actually a good function for vectors. Maybe you want conj?
so does merge
user=> (merge [1] [2])
[1 [2]]
I only suggested conj because it has the exact same behavior on vector input, if you aren't using merge / vectors you can ignore
my theory is you weren't doing what you thought you were doing
(ins)user=> (def a (atom {:a [1 2]}))
#'user/a
(cmd)user=> (swap! a update-in [:a] merge [:a :b])
{:a [1 2 [:a :b]]}
I can leave my data strucutre as a set but I was wondering if there was anything I'd lose by leaving it a set
The iteration order will change when you convert from vector to set.
btw, https://clojuredocs.org/clojure.core/distinct is a related function in the core lib.
sort
+ dedupe
could also be useful ( https://clojuredocs.org/clojure.core/dedupe )
@urbanslug I like how transducers work for that issue
(ins)user=> (defn dedupe-join [& vecs] (into [] (comp cat (distinct)) vecs))
#'user/dedupe-join
(ins)user=> (dedupe-join [:a :b :c] [:d :b :e] [:c :b :f])
[:a :b :c :d :e :f]
am I right in thinking that the :aliases
map in deps.edn is supposed to be used to override/add-to deps declared in the :deps
map ? Because when I use clj -R:my-alias
it makes no difference to the classpath
sorry I mean it only makes a difference with :extra-paths
:override-deps
doesn't seem to work
and I've checked it over and over
i.e. if I declare a dependency in the :deps
and then again with a different coordinate (local repo) in an alias it doesn't override it
but I can verify that local repo coordinate works by moving the dependency into :deps
(commenting-out the other one)
@octo221 I admit it's kinda weird, but as with a lot of things in Clojure, it's a la carte. -R == dep resolution changes -C == later classpath additions/overrides -M main options -O jvm opts -A == R + C + M + O
Is it considered bad form to create records for java Classes when wrapping a library? i.e if the user is going to get objects back FooA
FooB
... where they only contain static data (results) is it preferable to 1) return them as is 2) return them as it and provide accessor functions 3) convert them into maps 4) call bean so that the class is kept 5) unpack them into records so that they can use instance?
Im kind of torn between just return the objects while providing a protocol for converting into maps and unpacking then into records
@ghadi I used -A yet it didn't work
I think I only need -R as I only want to override deps
Hi! I have a vector with files: ["path/file1.txt" "path/file2.txt" "path/file3.txt"] and I'm reading with: (slurp file)
it sort of depends, but the best thing to do, if you want to merge them in to a single file, is to use http://clojure.java.io/copy and http://clojure.java.io/file and http://clojure.java.io/input-stream
but "queries.sql" is becoming a very large file and I want to split the content in smaller files
You could also explore (mapv #(conman/bind-connection db %) ["path/file1.txt" "path/file2.txt" "path/file3.txt"])
, with a caveat for transactions depending on the details of conman.
How can a make a request like this in clojure
curl -X POST -d @sample.json --header "Content-Type: application/json" --header "Accept: application/json"
? I was trying to do it using the library clj-http
and http-kit
with no luck(client/post ""
{:basic-auth ["user" "pass"]
:body "{\"json\": \"input\"}"
:headers {"X-Api-Version" "2"}
:content-type :json
:socket-timeout 1000 ;; in milliseconds
:conn-timeout 1000 ;; in milliseconds
:accept :json})
does adapting this not work?with httpkit that would be (untested):
@(client/post "" {:headers {"Content-Type" "application/json", "Accept" "application/json"}, :body (slurp "sample.json")})