Fork me on GitHub
#beginners
<
2021-12-10
>
zackteo03:12:32

If I have many (~15) maps that I want to call upon for tests, what's the best way I should go about defining them? It is too much that I wouldn't want to put it in the same file as my tests. Is putting them in a clj file called x_test_data.clj bad practice?

emccue03:12:04

If it's just data you can put them in x_test_data.edn

zackteo03:12:44

okay so the problem I have is that if i do that I can't quite run my tests in the repl

zackteo03:12:31

because the project im working on uses lein-modules, and typically for dev there is a dev folder to start the repl from

zackteo03:12:33

okay maybe let me asking another question :thinking_face:

zackteo03:12:45

Is there a clojure function to convert a relative file path to an absolute one?

hiredman03:12:28

load it from the classpath using http://clojure.java.io/resource, not directly from the filesystem

zackteo03:12:24

any suggestions on what i should do if my classpath is different from where i put my resource?

hiredman03:12:01

it isn't a resource if it isn't on the classpath

zackteo03:12:42

a hack I can do is to

(require '[cemerick.pomegranate :as pom])
(pom/add-classpath "....")

hiredman03:12:48

in general if you put it next to a clojure source file then it will be on the classpath, because clojure source code is loaded as a resource via classloaders

hiredman03:12:26

if you have test.clj file you can put your test.edn file right next to it

zackteo03:12:48

and not in resources?

hiredman03:12:53

usually by convention people don't intermingle their source code and resources

hiredman03:12:00

but they are all loaded the same way

hiredman03:12:10

you (require 'foo.bar) ultimately the resource "foo/bar.clj" is looked for

zackteo03:12:30

right but ideally I don't want to have to intermingle them

hiredman03:12:03

some projects will define a separate test-resources folder and setup on their tooling to include that when running tests

zackteo03:12:48

yeap I do have that - maybe the context is that i have a project using lein modules aka multiple lein projects in 1 project

zackteo03:12:44

I have a project-dev project where I'm expected to start my lein from but the code I want to run is in the project-core project

hiredman03:12:06

you know I used to work with the guy who started the lein project, he started it because he hated the maven multi module build we had at work

😂 1
hiredman03:12:33

so seeing that re-implemented on top of lein is really something

zackteo03:12:56

wow 😅 that i didn't know

hiredman03:12:24

once lein got big enough our boss made a massive git change to the repo over the weekend to switch from maven to lein

zackteo03:12:57

Meanwhile, I'm unfortunately not in the position to switch my project out of a lein-modules project :x

zackteo03:12:02

So I'm trying my best to make repl driven development in that project still good with these limitations i guess

zackteo03:12:34

So things have been alright due to the existence of :source-paths in lein

zackteo03:12:56

but now slurping in resources for tests in the repl doesn't work

zackteo03:12:55

my initial way was to define all my resources in a namespace like recon-test-data but putting all the data into a clj file/ns seems like bad practice

zackteo03:12:06

So I'm just trying to see if there's another way I can do it (cause the way of putting it into a ns was something my colleague commented on - wanting me to change it)

hiredman03:12:47

Sure, I dunno, I would just mingle it at not worry, especially for tests

zackteo03:12:21

Okay! Thanks for your advice! And the interesting bit of history haha

seancorfield04:12:08

You're swimming in the waters that lead to a monorepo and your life will be better when you get there.

seancorfield04:12:11

lein-modules is kind of a horrible idea 😞

😶 1
zackteo04:12:19

The irony is that it is a monorepo hahaha

zackteo04:12:40

but one with lein modules

seancorfield04:12:51

Oh god, that's even worse then! Switch to deps.edn and the CLI as soon as you can!

zackteo04:12:46

I'll try - personally haven't used deps.edn to know how that will work out

seancorfield04:12:06

We started getting into a mess with Leiningen as our repo grew and we switched to Boot in 2015 and then to the CLI in 2018. Life is so much better!

zackteo04:12:39

But I think I probably have to tread wisely as I make sure not to annoy my boss and earn his trust

seancorfield04:12:59

Ah yeah, you're pretty new at this place, as I recall?

zackteo04:12:45

Yeap! Just transferred department and team, and started being a Clojure dev at the start of november

seancorfield04:12:47

Yeah, you might get resistance trying to move away from "industry standard" Leiningen, unfortunately.

zackteo04:12:50

And other things I realise is that I'm the only one really doing repl driven development in a sense - I mean they do use a repl in great ways to inspect a running system

seancorfield04:12:02

It's a shame because it's really rigid and it's easy to outgrow it, in my opinion.

seancorfield04:12:16

Ah, yeah, that would mean they're not feeling the pain...

zackteo04:12:39

but from my understanding, they type into the repl when they use it so .... :x

zackteo04:12:48

Though, my boss introduce someone new (was doing another project in his team) into the same clojure team and have been directing him to the right resources

zackteo04:12:35

But I'm in the meanwhile just trying to smoothen the path so that when he starts working on the project there isn't too much difficult in him wanted to do repl driven development

seancorfield04:12:49

I spent all day today working in our legacy app, rewriting it to Clojure. It runs a Socket REPL. So I started the app, connected my editor to it, and eval'd code into it as I wrote it so the legacy app changes in real time. THAT is RDD.

zackteo04:12:55

which i think is most ok - just not for the tests

zackteo04:12:52

sometimes I think it is a weird scenario, like my boss went from (from what i understand) repl driven development with emacs+cider, to intellij+cursive (cause his laptop was reformatted and can't install emacs again) and idk if it was a matter of shortcuts or what but he seem to stop doing RDD

seancorfield04:12:11

I can't imagine ever going back from RDD. That's why I have socket REPLs running in the legacy apps. I can't do without it.

seancorfield04:12:43

It's how I debug our QA and even our production processes -- via socket REPLs inside live, running apps.

zackteo04:12:43

Neither can I. But okay we do have a nrepl running in our application. Which we do use for debugging. Which is great

zackteo04:12:05

Tho probably for company security reasons, not something we can easily just connect to in the editor (probably possible but haven't tried setting it up). And just evaluate code from the editor in

zackteo04:12:45

Just lein repl :connect ... and typing there

zackteo04:12:22

But all in all, am glad to be working with Clojure, just that I have to work around certain constraints and also hopefully gradually earn my boss' trust with time (and not annoy him instead 😅 )

1
seancorfield05:12:59

Hopefully, you can work to slowly modernize them and get them to move to a better monorepo setup.

seancorfield05:12:06

Send them links to my blog 🙂

zackteo05:12:22

Hopefully!

zackteo05:12:27

Will do! 😄

maverick10:12:38

I have a PersistentHashMap and I am doing select-keys on it. It is returning PersistenArryMap

Antonio Bibiano10:12:12

I think it's related to the size of the map, it's an implementation detail but if your map has more than 8 entries it's a PersistentHashMap if has less it's a PersistentArrayMap so i guess if you're selecting less than 8 keys you'll get your behaviour

Dler Osman10:12:33

Please fill out this survey on Covid-19. It takes less than 2 minutes https://forms.gle/eHhPDWAkMTwuqWhJA

pez11:12:10

Deleting this.

Lycheese11:12:38

Is there a way to list all dependencies and their versions with the clojure cli? (e.g. to find out if log4j is an indirect dep of my project and see all versions used)

flowthing11:12:20

clj -X:deps list

flowthing11:12:50

Or clj -X:deps tree to see the dependency chain.

pavlosmelissinos12:12:03

Take a look at tools.deps.graph as well if you're looking for something fancier: https://github.com/clojure/tools.deps.graph

Isaac Wooden17:12:12

What's a good function for merge-with to collect scalar values into a list? E.g. (merge-with ?? {:a 3} {:a 4} {:a 5}) -> {:a [3 4 5]} , the usual suspects of into/`conj`/`concat` don't really fit since the values don't start off as collections

Isaac Wooden18:12:40

Well, maybe this isn't a good example since you can just (map :a data) , how about turning something like {:a 1} {:a 2} {:b [3 4]} {:b [5 6]} into {:a [1 2] :b [[3 4] [5 6]]} ?

Sam Ritchie18:12:58

Map-values vector across each side first then merge-with into

Sam Ritchie18:12:57

Presumably you want non-clashing keys to have a vector wrapped around the singleton value in the result yeah?

Isaac Wooden18:12:41

Yeah, is there an easy way to do map-values without dipping into something like spectre?

pavlosmelissinos18:12:09

clojure 1.11 has clojure.core/update-vals

(->> [{:a 1} {:a 2} {:b [3 4]} {:b [5 6]}]
       (map #(update-vals % vector))
       (apply merge-with into))

Sam Ritchie18:12:52

Otherwise if you are stuck on an older version here is one way

Sam Ritchie18:12:28

Into keeps the value as a vector, concat would give you a lazy sequence instead

âž• 1
Isaac Wooden18:12:13

Makes sense, wish there were 1.11 packages available on the clojure/tools homebrew tap

Sam Ritchie19:12:46

Yeah definitely don't pull in sicmutils for that!

😄 1
Sam Ritchie19:12:52

Copy and attribute for sure

tschady17:12:47

TIL map-invert. Anybody know why it’s in clojure.set despite it not appearing to have anything to do with sets? Looks like it’s been there from the beginning.

Sam Ritchie18:12:05

Maybe because the keys form a set so the values will always be sets?

Sam Ritchie18:12:19

After transform… but I do not know the original reason!

hiredman17:12:54

clojure.set contains some bits for an in memory relational database

hiredman17:12:12

map-invert is used to implement clojure.set/join

💯 1
dpsutton18:12:27

I like to think that the set of values will be the keys and the cardinality of the map can decrease when doing this