[ANN] etran: added map-reduce comprehension

Serge Aleynikov serge@REDACTED
Sat Aug 21 02:59:35 CEST 2021

Dear Erlangers,

I just pushed the release 0.2 of the etrans application that adds a parse
transform for extending the standard list comprehensions with the ability
to fold a list, given the initial state.


This is similar to the lists:foldl/2 and lists:mapfoldl/2 functions:

Given: L = [1,2,3]

1. Fold Comprehension:

6 = [S+I || S = 0, I <- L].     %% Translates to: lists:foldl(fun(I,S) ->
S+I end, 0, L)

2. MapFold Comprehension:

{[1,2,3], 6} =
  [{I, S+I} || S = 0, I <- L].  %% Translates to: lists:mapfoldl(fun(I,S)
-> {I, S+I} end, 0, L)

As an avid user of list comprehensions, I always missed the ability to do
the fold on a list using a short-hand pattern syntax.  This etran library
lifts that restriction, potentially making the code more terse.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210820/2abf8a26/attachment.htm>

More information about the erlang-questions mailing list