A simple function below:
const L = a => L;
forms
L
L(1)
L(1)(2)
...
This seems to form a list but the actual data is not stored at all, so if it's required to store the data such as [1,2]
, what is the smartest practice to have the task done?
const L = (a) => {
// do somthing
return L;
};
I would prefer this concise arrow function style, and do not want to destroy the outer structure as much as possible. Surely, I understand some outer structure modification is required, but I am curious what is possible especially in functional style not OO.
The specification is simply to store data of the function chain.
Any ideas? Thanks.
An initial simplest approach would be:
const L = (a) => {
L.val = a;
return L;
};
L.val = L;
can do some, but no data accumulation.
{ [Function: L] val: [Circular] }
{ [Function: L] val: 1 }
{ [Function: L] val: 2 }
Notice:
Every list should be independent for the accumulation.
L(3)(4)
will return [3,4]
not [2,3,3,4]
with prior accumulation of another lists.
Advanced topic!
How to store data of a functional chain of Monoidal List?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…