Working as a mentor in the Education Working Group at The EEF, there are several tiny simple lessons that I’ve delivered over and over again. The on

Ode to the Robot Butt

submited by
Style Pass
2021-05-25 08:00:10

Working as a mentor in the Education Working Group at The EEF, there are several tiny simple lessons that I’ve delivered over and over again. The one in this article is so common that I already gave it a name: The Robot Butt Rule.

The situation usually arises when some exercise or p roblem requires the developer to do something with a list only if it is not empty. For instance, return its first or last element. To exemplify this scenario, let’s write a generic function for that scenario: it either returns an error if the list is empty or runs another function on the list if it’s not.

This is the spec of a function called if_not_empty, with 2 arguments of types F and L, respectively. It can return elements of one of two possible types: Error or Ok.

Elements of type F are functions that receive a non-empty list of elements of type X ([X,…]) and return an element of another type (Y).

Leave a Comment