[erlang-questions] Second order function lists:map

Franco Milicchio franco.milicchio@REDACTED
Tue Mar 10 17:03:00 CET 2009


On Mar 10, 2009, at 4:44pm, Franco Milicchio wrote:

>
> On Mar 10, 2009, at 4:24pm, Rob Charlton wrote:
>
>> Is this what you are after?
>>
>> paa(A) ->
>>  fun(L) ->
>>          lists:map(fun(F)->
>>                            F(A)
>>                    end, L)
>>  end.
>>
>> 7> G = test:paa(42).
>> #Fun<test.0.118673008>
>> 8> G([fun math:sin/1, fun math:cos/1, fun math:tan/1]).
>> [-0.916522,-0.399985,2.29139]
>>


Rob, what do you think of this solution?

paa(L) ->
     fun(X) ->
             lists:map(fun(F)->apply(F, [X]) end, L)
     end.


Thanks for your pointers!


-- 
Franco Milicchio <franco.milicchio@REDACTED>

DIA - Dept. of Computer Science and Engineering
University Roma Tre
http://plm.dia.uniroma3.it/milicchio/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2435 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090310/322bbd1b/attachment.bin>


More information about the erlang-questions mailing list