It seems fairly common to create a hierarchy of communities and collections which are initially empty. It's useful to be able to browse and search only those containing items.
I attach a version of the patch that was provided in
DS-343, updated to work with DSpace 4.2. It provides the ability to hide empty collections or communities under various conditions, and the ability to hide specific communities by providing their handles in the configuration. As was said in DS-343, this is two different features mashed together. However, once you have a filter in place, these are probably the two most common reasons for using the filter. I was wondering about a pluggable filter system, but that may be a step too far.