Filtering By Identity

I’m reading Functional-Light JavaScript by Kyle Simpson, and learning a lot! Today I learned about the functional programming utility known as ‘identity’. Identity is a unary function that simply returns its argument. A simple idea that can be powerfully applied, as JavaScript coerces the returned argument to boolean: > const identity = (arg) => arg > ["", false, "keep", null, undefined, "these"].filter(identity) [ 'keep', 'these' ] I’ve done something similar for years by filtering to boolean, or writing my own (I didn’t know it had this name) anonymous identity function. ...

June 27, 2024 · 1 min · Jake Worth

Don’t miss my next essay

Hear from me immediately when I post: no ads, unsubscribe anytime.