Closures in API design – theoretical limitations and best practices?

One possible practical compromise is to offer two choices: one which is the above and one which is minimally flexible, just offering the Iterator::map()-style callback:


Then simple applications can have a simple interface, and ones which want some refinement can use the more complex, possibly fragile one. (Fragile in that it opens many questions of what happens if it is used differently than the intended pattern; possibly those have simple answers in the particular case.)

1 Like