What Should I Be Using For If(Value.isNotBlank(), ..., _NoOp())

@Nad, great point!

categorySelector.isBlank() OR [My Table ].[Category].Contains(categorySelector)

Is an elegant solution. I’d still argue that someSelector.ifNotBlank(...) is a bit more readable, but I’ll be using your approach until we have that.

@Federico_Stefanato couldn’t we use SwitchIf(<condition>, RunActions(...))?

Seems to work here.

Edit:
The only reservation I have about this approach is that I find it more complex to parse at a glance what a condition is doing when it contains many OR and AND tokens. I suppose with some formatting it’s a bit more readable.

(
  someSelector.isBlank()
  OR
  [My Table].[someColumn].Contains(…) 
) 
AND 
(
  anotherSelector.isBlank()
  OR
  [My Table].[anotherColumn].Contains(…)
)

If logical operators could be chained then this might be an interesting pattern. Not sure it’s much more readable but at least operator preference is explicit.

(
  someSelector.isBlank().Or(
    [My Table].[someColumn].Contains(…)
  )
).And(
  anotherSelector.isBlank().Or(
    [My Table].[anotherColumn].Contains(…)
  )
)
3 Likes