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. ...