[erlang-questions] increment in map
Gleb Peregud
gleber.p@REDACTED
Mon Jul 26 21:51:45 CEST 2010
[{td, [],[W,X]} || {W, X} <- lists:zip([1,2,3], [1,2,3])]
On Mon, Jul 26, 2010 at 21:43, Wes James <comptekki@REDACTED> wrote:
> Nicholas,
>
> Thx - I realize I asked the question wrong. The list comprehension
>
> [{td, [], massage(W,Ls)} || W <- vp(Vp,Row)]
>
> will create a list in place, is there a way to create an increment
> value within this structure?
>
> I looked at a quick test with:
>
> [{td, [],[W,X]} || W <- [1,2,3], X <- [1,2,3]]
>
> but it creates:
>
> [{td,[],[1,1]},
> {td,[],[1,2]},
> {td,[],[1,3]},
> {td,[],[2,1]},
> {td,[],[2,2]},
> {td,[],[2,3]},
> {td,[],[3,1]},
> {td,[],[3,2]},
> {td,[],[3,3]}]
>
> whereas, I would like a one to one paring:
>
> [{td,[],[1,1]},
> {td,[],[2,2]},
> {td,[],[3,3]}]
>
>
> -wes
>
> On Mon, Jul 26, 2010 at 1:25 PM, Nicholas Frechette <zeno490@REDACTED> wrote:
>> You could use 'foldl' instead of map:
>> foldl(fun(Row, Inc) ->
>> ...
>> Inc + 1 %% Return value is the new value of Inc for the next call
>> end, Rows, 0).
>>
>> You could also zip seq(0, numrows) with your rows and unzip them inside the
>> map (though if you have a lot of rows, the above will be faster and leaner).
>>
>> Nicholas
>>
>> On Mon, Jul 26, 2010 at 2:38 PM, Wes James <comptekki@REDACTED> wrote:
>>>
>>> I have this code:
>>>
>>> map(fun(Row) ->
>>> {table, [{style, "width:700px; margin:5px;
>>> background-color:dddddd;"}],
>>> [
>>> thtd(Hdrs, [{td, [], massage(W,Ls)} || W <-
>>> vp(Vp,Row)])
>>> ]}
>>> end, Rows)
>>>
>>> and as I loop through the Row I would also like to send an increment
>>> in the massage(W,LS,Inc) call, but I don't see how I can do that
>>> within a list comprehension. Any ideas on how I would do this?
>>>
>>> thx,
>>>
>>> -wes
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> See http://www.erlang.org/faq.html
>>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>>
>>
>>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
More information about the erlang-questions
mailing list