Silver bullet for managing Null&Empty, single&List?

Hello,

I have been looking around but cannot quite find the solution I need.

Namely, one node, or designscript (or even Python), which is able to return true or false for Null, or Empty list arguments, either single or lists.

See diagram with my tests so far (I am using a combination of IsNull and IsEmpty nodes, but I bet I could expand this to counting lists, etc.).

Basically, the results should answer the question: isnull? or is empty? for both cases, and for both single data or lists.

Before I go crazy on this, I wish to make sure there isn’t some beautifully elegant, little solution that has been already established as best practice… :slight_smile:

Thank you

Not at my cpu to check, but perhaps List.Count(lst) == List.Count(List.Clean(lst)) & !(IsNull(lst));?

The main problem you’re running into is that null and empty are fundamentally different. Null is a value. Empty is a structure, specifically a list, which makes even more of a difference. You can’t directly compare the two.

The difference in assumed structure is what makes things tricky, because nodes will treat lists and items differently (which you can see with auto lacing). While changing the lacing or list levels to a specific structure will not treat each condition the same since one is looking at the input item and the other is looking at the input list. List levels might make things a bit more equal here but there will still be differences in how the structures are treated.

Python wrapped in a custom node is probably the best option. Python will allow you to specify exact conditions for an exact structure (the item) while the custom node will handle list levels.
OUT = (IN[0] == None) or (len(IN[0]) == 0)

EDIT: I’d be more curious to know when/where you have the need for this. Since these values represent fundamentally different scenarios, I’d be interested to see where you need to treat them as the same. Is it just for “cleanup”?

I am also quite curious here… the ‘use’ of it is not as direct as it might feel at first. :slight_smile:

Thank you Nick, but i cannot do this… :sob:

Any suggestion? How to make your line work for single elements and lists?

This does not work…:

Okay, this seems to be working with.
I duplicated the workflow for list or non list, and used the IF nodes to pass the correct one.

This returns the correct results while using:

  • list of mixed data (valid data, null and empy list)
  • one valid element
  • one null
  • one empty list

However, I know this is the poor idiot designer way, and there must be a better way to do this.

The python code is just the function to determine null, empty, or other. I suggest wrapping that function in a custom node so that you can control list levels and apply lacing logic as needed.

Again, null and empty deal with fundamentally different logic, so the more control you have over your situation the better. You will have to explicitly tell the node how to look at your dataset (via list levels).

You can see the same issue with your working code above. The logic works correctly but you had to specify the structure (list levels) for empty lists. You’d have to change this for each data structure you work with. Doing that at the node level makes this a single change based on context, rather than a rework in logic.