# Shouldn't List().ContainsOnly(List()) return true?

Seems related to:

I’m trying to check if two lists are identical.

E.g.

• `List(1,2).ContainsOnly(List(1,2))` returns true
• `List(1,2).ContainsOnly(List(1,2,3))` returns false

but now the weird one

• `List().ContainsOnly(List())` returns false, I expected true

The way around this is to use

• `List() = List()`returns true
and it works for the rest as expected
• `List(1,2) = List(1,2)` returns true
• `List(1,2) = List(1,2,3)` returns false

Community, have any thoughts on this? Does this seem expected to you? @jeo @Paul_Danyliuk @Federico.Stefanato @Johg_Ananda?

I think the answer is in the description of what `ContainsOnly()` does:

It’s searching for something … and you can’t search an empty list, so its false from the start. It doesn’t matter if you do:
`List().ContainsOnly(List("foo"))` - this isn’t true because an empty list doesn’t have it
`List().ContainsOnly(List())` - this isn’t true either because an empty list can’t have anything in it

Kind of like how zero can be true:

2 Likes

I see that perspective.

Another way to say this could be `List()` clearly only contains nothing, and therefore any other list whose only contents are nothing must also only contain nothing.

1 Like

Interesting question, I had to research this.

It seems that mathematics agree with you, the empty set is a part of all sets…

I agree with you that this is unexpected.

I would expect the following equivalency to always hold true:

``````ListA.ContainsOnly(ListB)
``````

is just a shorthand for

``````ListB.FormulaMap(
ListA.Contains(CurrentValue)
).And()
``````

and also this expression:

``````Sort(Unique(ListA)) = Sort(Unique(ListB))
``````

And this holds in all cases except if both ListA and ListB are `List()`, in which case all three expressions should return true, but only the latter two do. That strikes me as inconsistent.

1 Like