New Feature: Sparse array parameters

Earlier this week we released version 0.11.0 of the Pack SDK, which included a lot of changes. This version is live in the Pack Studio web editor, and CLI users can upgrade to it now. One of the new features I wanted to highlight is sparse array parameters.

To back up a bit, for every type of parameter that Packs support (String, Number, etc) there is an equivalent type that accepts a list of that type (StringArray, NumberArray, etc). All of the items in the list need to be of the same type, which is usually not a problem.

However it’s common for a user to want to pass an entire table column into an array parameter, and table rows can include blank cells. A blank cell in a number column is not a number, so Coda will throw an error before it even tries to run your formula.

image
(The error message could be clearer, we’re going to work on that.)

We couldn’t easily go back and change the behavior of the existing array parameters without risking breaking your Packs, so instead we introduced a new line of parameter types specifically designed to handle blank cells.

Every array parameter type now has a “sparse” variant (SparseStringArray, SparseNumberArray, etc) that allows for blank values, which are passed to your pack as the special value null. When writing your code you’ll need to plan for handle these possible null values, but usually that isn’t very complex (filter them out, fall back to a default, etc).

To check out sparse parameters in action, check out this new sample in the documentation:

The big question: should you use the regular array parameters or the sparse ones? In my opinion the sparse variants are more user-friendly and flexible and should be the default choice. However, if your logic really depends on the list not having any blanks then the regular array parameter would be a fine way to enforce that.

P.S. - The 0.11.0 release also previews a number of breaking changes that are coming next month. Check out the migration guide to learn more.

9 Likes