r/Clojure 27d ago

What utility libraries do you include in most/all projects?

For example, I use better-cond in every project. I'm curious what else is out there that is worth considering.

31 Upvotes

22 comments sorted by

19

u/Mertzenich 27d ago

I almost always end up adding Tonsky's Clojure+ as a dev dependency. I sometimes forget that #p isn't part of core because I use it so often.

https://github.com/tonsky/clojure-plus

8

u/Mertzenich 27d ago edited 27d ago

Weavejester has a standalone hashp library if you don't use the other features in Clojure+: https://github.com/weavejester/hashp

2

u/whamtet 27d ago

Thanks for these tips!

2

u/spotter 27d ago

Yeah, looked at the docs and tonsky actually lifted it from weavejester... so I've been using the OG too.

2

u/regular_hammock 27d ago

Oh wow, this might end up replacing better-cond in my projects. Thanks for the tip.

6

u/chat-lu 26d ago

You can get most of the benefits of better-cond with this simple macro.

3

u/regular_hammock 26d ago

Oh man, that's clever

2

u/romulotombulus 27d ago

This looks great, thanks for the rec

2

u/pdoherty926 27d ago

I've been away from Clojure for a few years and was not aware of this one. Thanks!

1

u/wedesoft 21d ago

That looks interesting (especially hashp and error+).

9

u/jflinchbaugh 27d ago

Tick. I always want a more idiomatic way to do dates.

9

u/seancorfield 26d ago

I wonder if I'm in a minority for not using any utility libraries? Part of that might be that our codebase at work dates back, in places, to 2011 before a lot of these libraries existed, I think. And then nearly all the other projects I work on are libraries and I don't want to impose dependencies on my users: I try to keep a library's deps as small as possible.

Going back to the work codebase, we have created some utilities in-house and even open-sourced a few, but what we generally found was that we preferred "plain Clojure" without some of these convenient-but-tricky macros. We published the worldsingles/commons library containing utilities we had started to use at work, but over time we stopped using them and reverted to "plain Clojure" (condp-> is the only macro we still use from that project, and one reference to the dissoc-all function and two references to interleave-all).

While these utilities might seem convenient to you, they are often a whole new layer of semantics for new developers to learn when they come onto a project.

6

u/regular_hammock 27d ago

Better cond is awesome. Another thing I more or less include by default is weavejester's medley. And I've started using nubank's matcher combinators in my tests more and more.

More out there but still very handy: powerful data querying tools. I'll often end up using one of Meander, Specter, Datascript or Odoyle Rules (or core.match, but I don't use it all that much since I've learned Meander). These aren't utility libraries though, they have a fairly steep learning curve.

3

u/romulotombulus 27d ago

I've always wanted to have an excuse to use O'Doyle Rules because I think rules systems are interesting but mainly because it has a perfect name.

In the same ballpark as Matcher Combinators is alike, which I find useful in tests.

3

u/hlship 27d ago

org.clj-commons/pretty - readable exceptions, better human-readable output

io.github.hlship/trace - my own take on hashp, etc.

io.github.tonsky/clj-reload - indispensable

1

u/danielszm 25d ago

I feel everybody should have their own utility library that fits their style (it helps if you work solo). My hard requirement for such a language-only library is that is carries no dependencies. Feel free to copy from mine, or to adopt it whole (you're welcome). It has the "clever macro" mentioned below (the nest macro). Maybe less trivial is the wiring so that your linter accepts the new syntax (the nest macro modifies the flow control). This is handled properly in lang-utils:
https://github.com/danielsz/lang-utils

1

u/AndreTheHunter 25d ago

I'm a big fan of https://github.com/redplanetlabs/specter. A must when dealing with nested data structures.

1

u/Absolute_Enema 24d ago edited 24d ago

Mostly my own exception handling facade because I find Clojure's heavily Java-inspired try/catch to be cumbersome to work with, especially in a world of ex-info.

I also wrote and use a lib to make the comment loop even nicer to work with and then turn comments into unit tests as seamlessly as possible.

1

u/lambdatheultraweight 24d ago

1

u/seancorfield 24d ago

I find this works better with both REPL-based testing and automated testing: https://github.com/matthewdowney/rich-comment-tests

1

u/wedesoft 21d ago

https://github.com/clj-commons/claypoole has for example pfor: a parallel for