I study Erlang, tried to write something like an analogue of the built-in "convolution" function lists:foldl
, in javascript:
foldl = (fn, x, list, acc) => { try { if(!acc) { acc = 0; } if(!list.length) { return acc; } return foldl(fn, x, list, acc + fn(list.shift(), x)); } catch(e) { return 0; } }; console.log( foldl((x, y) => x + y, 2, [1,2,3]) ); // 12
In this example, the "level of abstraction increases", the purity of the function is maintained. Is it acceptable to write (or try to write) code completely in a functional style, like in Erlang, in javascript? What could this ultimately lead to?
=>
there is too much. - nick_n_areduce
function - Grundylist
is changing - Grundy