ContainsOnly() does not function as it should

The “ContainsOnly(value, search)” function doesn’t work as it should. I get what you were trying to do, but it doesn’t make much logical sense - it uses AND instead of OR.

It says:
“Outputs True if only values in search exist in value.”

So, what should it’s output be for this example?
List(“Dog”, “Mouse”).ContainsOnly(“Cat”, “Mouse”, “Dog”)
According to the formal description for it, all values in the list exist in the search–so, it should return True.

And this one?
List(“Dog”, “Mouse”, “Cat”).ContainsOnly(“Mouse”, “Dog”)
This should return False as not only values in the search exist in the value.

But that’s not how it works… Currently, it only will return True when all values in the list are contained at least once within the search and all values in the search are contained at least once within the value This isn’t practically useful at all…

By the way, Coda already recognizes that I’m right syntactically, they built this logic into their filtering function:

If you add a filter to a table for a ‘Select Multiple’ column, it gives you six options, the first 4 are for logical (and/or type) groupings, the last 2 cover unique scenarios:

  • contains all of (and function)
  • contains any of (or function)
  • is exactly (and function)
  • does not contain (or function) this is the same as a ‘ContainsOnly().Not()’ function in theory
  • blank/not blank
  • count of

If there’s a strong reason for it functioning this way, then:

  • Its function name should be changed to match it’s description,
    OR
  • Its description should be updated for what it actually means and then another function should be added called something like “IsSubsetOf” or something.

For any who find themselves looking for how to achieve what ContainsOnly() should achieve, use this formula:
value=(value.Filter(value.contains(search)))

I just wanted to confirm the inconsistent behavior. The function and the description (and name) do not match. I do not quite get why does this bug exist for several months :frowning:
There are ways to work around it, but it is simply confusing the users.

1 Like

Here is an overview of the various ways to compare lists in Coda. ContainsOnly() does exactly what the name says it does. The comparison table also has links to pages that explain the formulas, with examples both in tables and on the canvas.

I’ve read the explanations on the formulas, and I’ve reviewed your pages. All of the formulas listed I find no fault in except for ContainsOnly(). I appreciate your expertise; however, I’m not convinced the logic of my original post was fully considered. I get that it seems like it functions as it should, probably because people often use the word “only” to mean “exactly” (especially because all it takes is switching the or-statement to an and-statement).

There are four main search functions that users use in programming and UI to filter content; paraphrasing they are: “Contains [All, Any, Exactly, Only].”

Your examples illustrate how ContainsOnly() currently works as a function that should be titled: “ContainsExactly()”.

If ContainsOnly() worked the way it should; if you were to add “Bread” to your “View of Unique Ingredient” list, then Eggs Benedict should still return true as it only contains Eggs or Bread (it doesn’t).

A more comprehensive way to read an only statement might be:

  • “All elements of set A contain only elements found in set B.”

Currently it’s programmed to work in alignment with this statement:

  • “All elements of set A are exactly the same as all elements in set B.”

Thankfully there’s a work around as I mentioned in my original post:
value=(value.Filter(value.contains(search)))

1 Like