Thinking in Functions, Part I: The Input/Output pattern.

Practical advice on how to design better functions.

The Input/Output pattern

A function that accepts a Field and returns a boolean validation verdict.

Similar to how you put the user’s needs first before making proper UX decisions, you think about what data your function accepts and returns in order to establish the boundaries of its future implementation.

Pattern at scale

Two functions are composable if the output of one can serve as the input to another.

A chain of functions where each preceding function’s output is the input for the next function.

In the end, functions are about transforming the data, so use all means available to ensure that transformation is coherent and efficient.

One more thing!

Function’s call signature defines its unit test.

Summary

Afterword

Follow me on Twitter to have a chat about functions, or programming in general. I’d be glad to hear your opinions and answer your questions.

Full-stack developer, progressive web enthusiast. Read more of my publications on https://redd.one