This is more of a feature request: skipmissing is useful, as would be skipnothing, if it existed. I know it’s easy to filter the nothing values away, but it’s also nice to drop the Union element type, as is achieved with collect(skipmissing(arr)).
I could make a PR for this, but the code would be almost identical to that underlying skipmissing.
I think the intention is to make missing stand for missing values, which propagate kind of semi-automatically when appropriate, and nothing an indicator of situations that there should be a value but there isn’t one and the caller should take explicit action to deal with the situation.
So I am not sure that skipnothing is that useful. In any case, you have
The main distinction I can see between filtering with filter(!ismissing, ...) and collect(skipmissing(...)) is that the resulting collection no longer has element type Union{Missing, ...}. I do not know of a similarly terse way to drop the Union element type for Nothings, when dropping the nothings in a collection, which is an explicit action to deal with the situation.
isnothing is not a function, but otherwise this seems like a good alternative: [x for x in xs if x != nothing].
Of course, you could do the same to remove missing values from an iterable, and yet skipmissing exists as a convenient utility function. I still don’t see any difference in utility between skipmissing, and a potential skipnothing function. From the documentation, it seems like skipmissing is motivated to ease reducing iterables containing missing values without getting a missing result. The same problem exists when reducing iterables containing nothing values, except that the reduction would most likely error instead of producing a nothing result.
Anyway, this is just a suggestion. I personally have to deal with nothing values far more than I have to deal with missing values, and I’ve often thought that skipnothing would be useful.
This works very well when x is a Vector, however in case x is an Array the resulting is a Vector. Is there a way to do it dimension-wise and keep the shape of Array?
There’s no way to know if each dimensional slice will contain the same number of nothings, but you can filter each slice and then concatenate the equal-length slices, e.g.