Fork me on GitHub
#clojure
<
2018-08-21
>
ilikeOPHeroines00:08:54

Does anyone here use Windows for clojure dev?

the2bears00:08:37

No, sorry... just Mac and Linux.

dpsutton01:08:11

@danial.javady check out this clojureverse thread

colinkahn01:08:51

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.

colinkahn01:08:51

Error I get is IOException Stream closed java.io.BufferedReader.ensureOpen (BufferedReader.java:122)

dpsutton01:08:11

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

dpsutton01:08:10

Invoked not involved. Sorry on mobile

colinkahn01:08:30

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?

dpsutton01:08:47

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

colinkahn01:08:40

Ok, thanks. It sounds like this pattern might not be as common as I imagined it would be.

dpsutton01:08:16

It's deprecated but could be useful to see how others have tackled it

dpsutton01:08:04

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

colinkahn01:08:52

Ah ok, interesting. read-lines is definitely more of what I had in mind. Thanks, I'll do a bit more research on it.

andy.fingerhut01:08:35

@danial.javady On multiple occasions I have seen @seancorfield mention that he likes using WSL on Windows for Clojure dev (and probably other purposes)

emccue04:08:34

interesting error on Long/valueOf

emccue04:08:43

seems to be failing on 160

ghadi04:08:28

that's a letter l ell, not a 1 (numeral one)

urbanslug11:08:30

Hey I'm doing something like (comp vec set merge) to update a vector but remove duplicates if the merge introduces one

noisesmith16:08:38

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?

urbanslug16:08:22

conj would create a vector inside another

urbanslug16:08:26

(conj [1] [2]) => [1 [2]]

noisesmith16:08:42

so does merge

user=> (merge [1] [2])
[1 [2]]

noisesmith16:08:46

I only suggested conj because it has the exact same behavior on vector input, if you aren't using merge / vectors you can ignore

urbanslug16:08:12

hmmm this works differently with update-in and swap 😛

noisesmith16:08:21

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]]}

urbanslug11:08:50

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

urbanslug11:08:19

since the collections api fns would still apply to it

Marc O'Morain11:08:47

The iteration order will change when you convert from vector to set.

urbanslug11:08:21

you mean the ordering of the collection?

urbanslug11:08:34

I don't need ordering for this

Marc O'Morain11:08:35

btw, https://clojuredocs.org/clojure.core/distinct is a related function in the core lib.

urbanslug11:08:17

yeah my composed function is slow

urbanslug11:08:32

let me try distinct

nha11:08:52

sort + dedupe could also be useful ( https://clojuredocs.org/clojure.core/dedupe )

noisesmith16:08:04

@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]

urbanslug16:08:16

damn my transducers knowledge is lacking 😛 I need to read up on them

octahedrion16:08:55

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

octahedrion16:08:31

sorry I mean it only makes a difference with :extra-paths

octahedrion16:08:45

:override-deps doesn't seem to work

octahedrion16:08:55

and I've checked it over and over

octahedrion16:08:09

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

octahedrion16:08:51

but I can verify that local repo coordinate works by moving the dependency into :deps (commenting-out the other one)

ghadi17:08:42

@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

ghadi17:08:09

I would appreciate a shortcut for R + C only, as that's a common coupling

beoliver17:08:04

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?

beoliver17:08:16

Im kind of torn between just return the objects while providing a protocol for converting into maps and unpacking then into records

pablore20:08:34

Think about what use cases your users might want to use

octahedrion17:08:24

@ghadi I used -A yet it didn't work

octahedrion17:08:43

I think I only need -R as I only want to override deps

aarkerio21:08:52

Hi! I have a vector with files: ["path/file1.txt" "path/file2.txt" "path/file3.txt"] and I'm reading with: (slurp file)

aarkerio21:08:16

but what is the best way to merge all the text in a single string?

aarkerio21:08:36

I mean, to merge all the files

hiredman21:08:31

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

aarkerio21:08:04

I mean, I have this:

aarkerio21:08:05

(conman/bind-connection db "sql/queries.sql")

hiredman21:08:21

if you want to merge them in memory, use str

hiredman21:08:35

(apply str (map slurp ...))

aarkerio21:08:38

but "queries.sql" is becoming a very large file and I want to split the content in smaller files

aarkerio21:08:07

ok, I see the "apply" and the str, thanks a lot!

gaverhae21:08:59

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.

pavani22:08:24

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

dpsutton22:08:08

(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?

gaverhae23:08:45

with httpkit that would be (untested):

@(client/post "" {:headers {"Content-Type" "application/json", "Accept" "application/json"}, :body (slurp "sample.json")})

gaverhae23:08:12

Note that httpkit is async by default so you have to force (deref, @) the return value if you want to wait for it

gaverhae23:08:41

(where client is from :require [org.httpkit.client :as client])