Coda with Filters or ForEach?

Exploring alternative approaches to assess currentValue

Christiaan Huizer
5 min readJul 1, 2024

--

In the community the active pack promotor Troy Larson solved an interesting puzzle.

Labeling solutions as ‘simple’ in the Coda community can be misleading. If they were truly simple, users wouldn’t need to ask for help. It’s beneficial for all Coda users to acknowledge that the tool can be challenging at times.

Recognizing this has two key benefits:

  1. It alleviates the frustration of not immediately grasping a solution. You’re not ‘stupid’ for finding something difficult; you’re dealing with a sophisticated tool.
  2. It encourages dedicating time to improve your skills. Like any powerful tool, Coda requires practice to master.

This reminds me of my son’s approach to math: he would read problems without doing exercises, which proved ineffective. Similarly with Coda, real proficiency comes from hands-on problem-solving and consistent practice.

As my logic professor, de Jong, often said: ‘Develop an intuition through training.’ This applies perfectly to mastering Coda. Embrace the challenges, practice regularly, and watch your skills grow.

The proposed solution by Troy

The solution was provided by Troy Larson who makes name and fame by promoting packs.

[A].Filter(Not([B].Contains(CurrentValue)))

My contribution

I decided to share my contribution because I could not easily read the the formula and one of my criteria is that by reading out loud a formula, it should be clear how the formula operates.

_A.Filter(CurrentValue.Contains(_B).Not())

This one you can read as:

Filter the list named A and check for each item if it does not contain an item from list B and give us that outcome.

I believe in patterns. The more patterns you can see, the easier it gets to write solutions you can explain and maintain.

When Ximo thanked us for our contributions, he admitted that he confused ForEach() with Filter(). That is not uncommon. Before I write about key differences, first a few words about patterns.

Why patterns matter

A while ago I wrote about patterns in relation to lowering the floor.

This principle of continuous learning and practice is fundamental to my work as a Coda expert. My role extends beyond merely finding solutions; it encompasses three critical aspects:

  1. Problem-solving: Identifying the most effective solution for each unique challenge.
  2. Efficiency: Developing the ability to arrive at solutions quickly, optimizing both my time and the client’s resources.
  3. Communication: Articulating the solution clearly to the in-house maker, ensuring they understand not just the end result, but the logic and construction of the formula.

Filter & ForEach

Have a look on the outcome when we replace Filter with ForEach:

ForEach instead of Filter

Instead of a list of numbers, we have a list with true and false. This logic reflects perfectly the ForEach function: you evaluate each item in the list. The outcome with the function Contains() is : yes it contains this number (true) or no it does not contain this number (false).

The rule of thumb is that when you look for values living in the list you evaluate, you apply Filter(). However when you want to evaluate the properties of all the items in the list, you apply ForEach(). You can also say: ‘for each item in this list …..’´. Note that I write ‘each item’, this means that the list you output is not getting shorter or longer.

The older name FormulaMap(),likely borrowed from Lisp, one of the earliest programming languages, introduced the concept of mapping lists, which was later adopted and refined in other languages like JavaScript.

const numbers = [1, 2, 3];
const double = (x) => x * 2;
const doubledNumbers = numbers.map(double); // [2, 4, 6]

This example perfectly illustrates the concept of “mapping” a function over a collection of data, which is exactly what Coda’s formulaMap() does in our docs. It’s a powerful and concise way to transform data as you see below.

coda is easier and faster than JS

As said before, forEach() does not modify the length of the list (or Array as a list is named in JavaScript) , even if you only see commas on your screen, the items in the list are ALL evaluated by the ForEach and returned (sometimes as blanks). The Filter() function reduces mostly the list and gives back the items fitting your evaluation criteria. When there is no fit, none is returned, when they all fit, all are returned. However most of the time you get a subset back of the list you evaluate.

In short: Filter() selects items without modifying them based on a condition (outputs only if true). ForEach() transforms each item in a list, based on an argument (do this, with this item for every item).

I hope this blog inspires you to enhance your Coda skills. Embrace the challenge and persevere — your efforts will pay off. As you master these techniques, you’ll unlock new possibilities for creating powerful, efficient solutions. Remember, every expert was once a beginner. Keep learning, keep building, and watch your Coda proficiency soar!

I hope you enjoyed this article. If you have questions feel free to reach out. My name is Christiaan and blog about Coda. Though this article is for free, my work (including advice) won’t be, but there is always room for a chat to see what can be done. You find my (for free) contributions in the Coda Community and on Twitter. the Coda Community provides great insights for free once you add a sample doc.

All the AI features we are starting to see appear — lower prices, higher speeds, multimodal capability, voice, large context windows, agentic behavior — are about making AI more present and more naturally connected to human systems and processes. If an AI that seems to reason like a human being can see and interact and plan like a human being, then it can have influence in the human world. This is where AI labs are leading us: to a near future of AI as coworker, friend, and ubiquitous presence. I don’t think anyone, including OpenAI, has a full sense of all of the implications of this shift, and what it will mean for all of us. — source: Ethan Mollick from One Useful Thing.

More about Coda AI and Coda Brain:

--

--

Christiaan Huizer
Christiaan Huizer

Written by Christiaan Huizer

I write about how to Coda . You find blogs for beginners and experienced makers. I publish about 1 / week. Welcome!

No responses yet