mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-10-20 20:53:19 +02:00
d09b4e3c87
* lib: introduce `foreach` = flip map
The main purpose is to bring attention to `flip map`, which improves
code readablity. It is useful when ad-hoc anonymous function
grows two or more lines in `map` application:
```
map (lcfg:
let port = lcfg.port;
portStr = if port != defaultPort then ":${toString port}" else "";
scheme = if cfg.enableSSL then "https" else "http";
in "${scheme}://cfg.hostName${portStr}"
) (getListen cfg);
```
Compare this to `foreach`-style:
```
foreach (getListen cfg) (lcfg:
let port = lcfg.port;
portStr = if port != defaultPort then ":${toString port}" else "";
scheme = if cfg.enableSSL then "https" else "http";
in "${scheme}://cfg.hostName${portStr}"
);
```
This is similar to Haskell's `for` (http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Traversable.html#v:for)
* mass replace "flip map -> foreach"
See `foreach`-introduction commit.
```
rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /foreach /g'
```
* Revert "mass replace "flip map -> foreach""
This reverts commit
|
||
---|---|---|
.. | ||
accessibility/mousetweaks | ||
altcoins | ||
audio | ||
backup | ||
display-managers | ||
editors | ||
gis | ||
graphics | ||
kde | ||
misc | ||
networking | ||
office | ||
radio | ||
science | ||
search | ||
version-management | ||
video | ||
virtualization | ||
window-managers |