New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: introduce forEach
= flip map
#64723
Conversation
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)
See `foreach`-introduction commit. ``` rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /foreach /g' ```
I can add release doc if this is going to be merged. |
@volth I agree with your sarcasm! But OTOH I'd want We can try to amend documentation, to teach people about |
How about just naming this |
@infinisil I'd reserve |
This should be |
This reverts commit 3b05343.
See `forEach`-introduction commit. ``` rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /forEach /g' ```
foreach
= flip mapforEach
= flip map
lib: introduce
forEach
= flip mapThe main purpose is to bring attention to
flip map
, which improvescode readablity. It is useful when ad-hoc anonymous function
grows two or more lines in
map
application:Compare this to
foreach
-style:(the example was taken with modifications from apache-httpd module)
This is similar to Haskell's
for
(http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Traversable.html#v:for)Extracted and simplified from a more radical approach in #57091.