My function takes an optional parameter, type, which is used to filter through a collection. However, the filter should only apply if the parameter is passed in (in other words, non-null). If the filter is not passed in, it should not be applied. How can I write my logic to reflect this? What I have now is - if( other conditions && ( Type == null || (Type != null && Order.Type == Type ) ) )    return val += Order;But this feels clunky and wrong. Is there a way I can simplify my logic here?
Apply filter only if not null
code quality;code reviews;conditions
The OP has stated in a comment that the language used has short-circuiting Boolean operators, so this could be written as:if( other conditions && ( Type == null || Order.Type == Type ) )    return val += Order;