Lib.optional considered harmful

This has been bugging me for a while, but I’ve never gotten around to writing something coherent about it. So I’ll just put the idea here since I’m curious if the community agrees.

I don’t like lib.optional. I think its highly counterintuitive that it wraps the result in a list. Here’s an example of an abuse:

Can’t we just use lib.optionals instead? Yes, it requires two additional characters ([]) but I think that is well worth the clarity.


generally I use optionals + [ ], even for single elements, just to avoid this scenario. Also makes adding new elements easier on the diffs.

I like the idea.

Btw, stats:

$ rg  "optional " | wc -l
$ rg  "optionals " | wc -l