What general-purpose commands do you usually end up adding to your projects?

question

#1

Related to this response from Stefan,

What commands do you usually end up adding to your projects to get around common nuisances?


Surprising struct equality test
#2

I use this for unit tests:

"Lenient comparison operator for `struct`, both mutable and immutable (type with \\eqsim)."
@generated function ≂(x, y)
    if !isempty(fieldnames(x)) && x == y
        mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
    else
        :(x == y)
    end
end

#3

Not sure if there is a built-in command for listing files in a directory but I use this one almost everywhere!

searchdir(path, key) = filter(x -> contains(x, key), readdir(path))