Como desarrolladores, no queremos utilizar el tiempo de nuestros sprints debuggeando bugs, y no queremos ser llamados a las 8 de la noche de un Sábado porque nuestro software está roto. Queremos tener confianza en lo que hacemos, necesitamos un héroe que nos resguarde y proteja de los errores que podrian ser fácilmente evitados. Necesitamos programar más defenisvamente! Necesitamos… contratos???

El comportamiento inesperado puede causar bugs

Cada vez que programamos definimos contratos, aún si no lo hacemos conscientemente, cuando definimos una función, definimos un contrato en el que declaramos los parámetros que recibe y la relación y restricciones que pueden tener. …

Lo dije antes y lo diré de nuevo, Google Sheet es una herramienta espectacular para aprender algunos conceptos de programación funcional. Por ejemplo, el hecho de que no nos importe si una celda es un valor constante o el resultado de una función nos debería gritar transparencia referencial. También, la forma en la que escribimos lógica condicional se parece más al operador ternario que a la sentencia if imperativa, lo que nos muestra cómo podemos construir un programa en donde todo es una expresión.

Pero no todo es color de rosas, las funciones de Google Sheet no pueden componerse para…

I said it once, and I’ll say it again, Google Sheet is an awesome tool to learn some Functional Programming concepts. For example, the fact that we don’t care if a cell is a constant value or the result of a function should scream referential transparency. Also, the way we do conditional logic resembles more to the ternary operator than the imperative if statement, and that shows us how to construct a program where everything is an expression.

But is not a bed of roses, Google Sheet functions can’t be composed together to form newer richer functions, which is the…

As developers, we don’t want to spend our sprint time hunting bugs, and we don’t want to be called at 8 pm on a Saturday night because our software is behaving strangely. We want to have confidence in what we do, we need a hero that guards us and protect us from making mistakes that could have been easily avoided. We need to start programming more defensively! We need… Contracts???

Unexpected behaviour can cause some serious bugs

Every time we program we define contracts, even if we don’t do it consciously when we define a function we define a contract stating the parameters it can receive and…

We use TypeScript because we want to restrict how we program, with the idea that those restrictions will make us write safer code. On that path, we can find a feature of the language called literal types, which will enable us to fasten the seatbelt a little bit more.

This feature can have some quirks related to type inference, so in this post we’ll investigate it using dtslint, a very powerful tool created by Microsoft that allows us to test our types.

We can think about our types as Sets, meaning string includes all possible strings, number all numbers, booleans

Compose all the things 🎉

Functional Programming is all about composing functions together and that means we need to make the output of a function to serve as the input of the next one. In order to do so, it’s convinient to make functions have a similar “shape”, thats why in lambda calculus all functions are 1-ary, meaning they all receive one argument and return one value.

In modern JavaScript you can achieve that by using arrow functions and passing one parameter at a time, but we lose the ability to call our function with all the parameters at once.

Thats when curry-ing comes…

Hernan Rajchert

I’m a Software Engineer focused on Web Technologies (full stack). I ❤️ typed languages and FP.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store