* glob is an i/o operation: impure
* load_file is an i/o operation: impure
* data.append serializes part of the execution order
---
Interestingly, GPT4 does pretty ok:
files = glob.glob('*.jpg')
with ThreadPoolExecutor() as executor:
data = list(executor.map(load_file, files))
---Separately, if just going for concurrency for i/o, async/await is pretty amazing:
tasks = [load_file(file) for file in glob.glob('*.jpg')]
data = await asyncio.gather(*tasks)
A lot less program transformation needed as it's essentially sugar over promises, and avoids much of the need to restructure code beyond the coloring problem. So I'm not as much about the case for a compiler here..