lib: introduce `forEach` = flip map (#64723)
* 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 3b053431. * mass replace "flip map -> forEach" See `forEach`-introduction commit. ``` rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /forEach /g' ``` * rename foreach -> forEach * and one more place * add release notes
Please register or sign in to comment