Is there something like sublist or unpack() in Microscript 2.0?
I would like to summarize part of a list but I just don't know how.
I would like to summarize part of a list but I just don't know how.
MicroScript you can use all the methods that list has in JavaScript.
If you accept combining MicroScript and JavaScript code you can write a function that would perform destructuring during rewriting.
// javascript
function Spread( list ){
return list.map(innerList => {
if (Array.isArray(innerList)) {
// If the element is an array, we only expand it to the first level
return innerList;
}
return innerList; // If it is not an array, we return it unchanged
});
};
// Creates a new object from a list that has a variable
// - element 0 - string - class name
// - element 1 - list - with as many fields as needed to create the object
function Bulid( data ) {
return new global[ data[0] ]( ...data[ 1 ] )
}
global.Bulid = Bulid;
global.Spread = Spread;