If you are wondering how the transformations involving map were arrived at, you might want to take a look at
Re: Turning foreach into map?, written by
tlm, whose response in this thread (somewhat ironically) was slice-based, rather than map-based.
Caution: Contents may have been coded under pressure.