Level up your `.filter` game
A really *smart* introduction to functional programming.
Adam Gieseâs âLevel up your .filter
gameâ does something really interesting and helpful: it introduces a bunch of fairly sophisticated functional programming concepts without ever mentioning functional programming and without ever using any of the jargon associated with those terms.
âLevel up your .filter
gameâ gives you a reason to use some standard FP toolsâcurrying, higher-order functions, compositionâin your ordinary work. Itâs pitched at working JS developers. It gives a real-world example of wanting to filter search results based on user input. It shows the utility of defining a bunch of small functions which can fit together like LEGO.
Filters are an essential part of JavaScript development. Whether youâre sorting out bad data from an API response or responding to user interactions, there are countless times when you would want a subset of an arrayâs values. I hope this overview helped with ways that you can manipulate predicates to write more readable and maintainable code.
I commend the piece to you not so much for the explanation of how to use JavaScriptâs Array.prototype.filter
effectively (though it has some good suggestions that way!) but primarily as a great example of the kind of pedagogy we need a lot more of to demonstrate the value of functional programming in ordinary, day-to-day development work.