4 ms·
Odd that you find closures weird. I use them everywhere that I can because it allows you to make your library more modular and, at the same time, allows you to
by mmstick 10y ago
Odd that you find closures weird. I use them everywhere that I can because it allows you to make your library more modular and, at the same time, allows you to write unit tests for otherwise impossible functions to test without dependency injections and other convoluted external setups that won't pinpoint the cause of an error very well.
Case in point, in the Ion shell that I am working on, I have a shell expansion module within that takes a structure containing closures that are used to grab and expand array variables, string variables, tilde variables, and process expansions.
Because of this, the module can live as an entirely separate piece of software with no dependency on the specifics of Ion, and I can write reduced unit tests that extensively test every component. I could strip it out of Ion and use it with a completely different shell project. That shell would just have to provide the batteries (closures) that define what to do with certain tokens.