[ANN] etran: added map-reduce comprehension

Serge Aleynikov <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CANt451=7yto9rMvKJVNC63B-Ct490oj+SRRHEqpSUJtZOv+XYg@mail.gmail.com>
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.

https://github.com/saleyn/etran

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.

Enjoy,

Serge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.