0

I recently came across a Stackoverflow question, and in the comments there was a discussion about the usage of the word "filter".

In the comments, someone said this:

Filtering at most one value has the same sense as iterating over at most one value. Both words imply more values.

I was curious about whether this is actually the case. Does the verb "filter" imply more values?

If I have a box containing either one or zero items, it is pretty strange to ask someone to remove all items from the box, if the number of items being at most one is known beforehand. One rather talks about removing the item from the box if it is present.

But what about filtering? Is it conventional to use the word "filter" when at most one value is present?

If not, what would be the alternative?


Note: the link to the particular Stackoverflow question might get some insight of the context of this question.

Related: Sieve vs filter? Are they opposites?

  • You could definitely sort one value, or none even. So, fine, theoretically as well practically in technical context. HTH. – Kris Feb 25 at 11:04
1

What I believe the comment you refer to is trying to say is that software concepts such as filter, map, and forEach are generally used when you're processing collections of arbitrary size. It's possible for the collections to be empty or have just one element, but those are just boundary cases.

But if the collection type is defined to have either zero or one element, it makes less sense to use these general purpose terms to refer to processing the element; it feels strange even calling this a "collection" when it's just one optional value. ifPresent is a better description of the operation that calls a function if there's a value, but does nothing if there's no value.

However, the original poster there has a point. The optional type does have generic collection methods such as filter and map, so it's somewhat inconsistent that it doesn't have forEach for completeness. The difference may be that filter and map are used to return a new collection based on the original, and there's no obvious alternative names for these operations in the at-most-one-value case.

  • "...and there's no obvious alternative names for these operations in the at-most-one-value case" because it's an instance of the generic case. See my comment at OP. – Kris Feb 27 at 9:28
  • I'm talking about whether there's a word when the input is known a priority to be just zero or one item. Similar to the way we use "either or" when we're talking about selecting from just two items, versus "any of" when the number of items is arbitrary. – Barmar Feb 27 at 19:01
-1

The Oxford Dictionary Online has a number of different definitions of the word filter ranging from the original concept of removing contaminents or valuable particles from liquids to the more metaphorical "move slowly" applied to traffic or a group of people as in "The players filtered onto the pitch."

The use of 'filter' on the StackOverflow thread is a technical one specific to data processing. Obviously if you 'filter' a dataset for one value, then 'filter' the resulting set for the same value you will return all the elements in the resulting set, even if the resulting set contains one or zero elements.

This is different from using a physical filter (such as scientific filter paper) on a contaminated liquid where repeated filtering can remove more impurities than filtering once even though the grade of filter is identical. This is because physical filtering is an analogue process and some marginally sized particles can be missed at the first pass.

You express concern that 'filter' might be applied to an empty box or a box containing only one object but that is confusing only because you are applying the IT term to the real world. In IT you can apply a filter to a set containing only one element, an empty set or a set containing none of the required elements and you return either an empty result set or a result set with only one element. However in the physical world no one would talk about 'filtering' the contents of an empty box or a box containing only one object, the term would have no meaning in that context.

In answer to your final question the answer is 'no' in general terms, people do not talk about 'filtering' one object. They might talk about filtering mud, for example, to retrieve a single gold ring they knew was lost in the mud but they would be talking about removing the gold ring from the hundreds of thousands of particles and billions of molecules of water making up the mud, a very different thing from retrieving a ring from a box containing only that ring.

'Filter' has, as I said, a number of different meanings and the IT term is one, very specific one which does not apply outside the IT context.

  • See also my comment at OP. – Kris Feb 25 at 11:05
  • @Kris I can see how sorting (and filtering which is a different process) a single row in a dataset makes sense, but how does sorting (that is placing in some defined order) or filtering (extracting what is required or not required from a mixture of liquids and solids) make sense in a physical context where there is only one object to process? Note that I covered the case of there being only one desired object in a sea of other objects in my answer. – BoldBen Feb 25 at 12:53
  • 1
    @BoldBen If your filter is to look for green objects but you only have a red object under consideration—then you end up with a result that has zero objects. You have filtered the single object out of the result. – Jason Bassford Supports Monica Feb 25 at 16:20
  • @JasonBassford But what sort of filter would you be using in a physical context to do that task? I don't see that anything like that exists. It exists in data processing but not in the physical world. Also if you are filtering for green objects you are rejecting any objects which are not green. If there are no green objects you are still filtering the multiple non-green objects, it's just that the filter doesn't find any of the target objects: you are still filtering multiple objects. If there are neither green objects or non-green objects there is nothing to filter. – BoldBen Feb 26 at 11:24
  • There is such a thing as a mental filter. Just because a filter doesn't have a physical existence, doesn't mean it doesn't exist. For instance, any of the forms of agnosia. (Unless you want to say that's really a physical filter in the brain itself.) A single thing can be introduced to that filter. That doesn't mean it's still not processed as any number of multiple things would also be processed. It simply acts a single time rather than multiple times. But, back to the physical, stick a single rock into a sieve, and it will still prevent that larger object from passing through. – Jason Bassford Supports Monica Feb 26 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.