Add more interaction with array in friendlier manner.

sampleuserhere

Active member
Say,

  1. Combine multiple array.
  2. Retrieve all array child values without the index and with custom separator.
  3. Order array based on certain rules, like alphabetical, numerical, reverser
  4. Retrieve certain array child with filter.
So far the workaround is impratical, I have to either loop them or do certain sorcery stunts to get the results I want.

A native built-in would be preferred and convenient for the end user.
 

Quidn

Passionate Member
  1. Combine multiple array.
  2. Retrieve all array child values without the index and with custom separator.
  3. Order array based on certain rules, like alphabetical, numerical, reverser
  4. Retrieve certain array child with filter.
So far the workaround is impratical, I have to either loop them or do certain sorcery stunts to get the results I want.

Sorry but I think workarounds are not so impractical. Except for # 3, rest are might be done by two steps - Iterate Array and an Action, as you already knew.

To be noted, kind of # 3 isn't supported by native functions even in general programming languages(though, so easy to be done compared to MD).

Both of # 2 and # 3 are hard to be implemented for general use. It doesn't mean to implementation is so difficult, but there are too many things to be considered when it comes to be a general function.
For an example:

Arrays can having children array or dictionary, so how to handle that? It must be differs to each user's needs, then does it have to be prepared by plenty of options to be fits-all? How to keep it straightforward while so many options have to be applied?
This is why that kinds of things have to be done by custom functions.

If you really want to do some advanced processing, I'd recommend "HTTP Shortcut". Quite different from its name, it can be used as an external JavaScript interpreter(and even more powerful features are integrated) for MacroDroid.
i.e., Process the parameters sent from MD*, and then return the result** back to MD.
*: Yes, you have to invoke HTTP Shortcut twice. Once to send parameters, once to get the return value. :eek:
**: Oh, this can be done by "Intent Received" by "Wait Until Trigger", and this way'd much better. (EDITED)

I don't doubt that features you suggested would be useful, but it seems hard to find the way actual implementation. If you have some detailed idea to implement # 3 as a general feature, sharing would be helpful.
 

Quidn

Passionate Member
The functions you mentioned are database-like functions, but since the concept and purpose of array/dictionary(object) are very different to databases, general programming languages also don't have such* functions.
  • *: (EDIT) "Such functions" refers to # 3 or similar, and others are supported by native ones in general. This was missed during I separate that sentence into a new reply rather than edit the former one.

This is beside the point but there are many kinds of database model even. Several just don't support sorting at all and many of them recommended to not to do sorting by value. Of course it's about for large-scale, but the point is not many type of data could be sorted. Just for reference.

Perhaps one day MacroDroid might natively supports SQLite and/or JavaScript then many problems including very complicated sorting would be solved by so easily.

Imagine that we can execute this through a native action like Shell Script action!

JavaScript:
'use strict';

const { someArray } = md.lv(['someArray']); // Get local variables as an object, by variable names in the array of first parameter

if (! Array.isArray(someArray)) {
  md.throw('Retrieving array failed'); // Return the string as an error
}

const result = md.lv({ someArray: someArray.sort(), }); // Set local variables by the object of first parameter

md.return(result); // Return the value as result

Oh dear I'm already so excited. 😵
I'll do happily implement anything requested on this forum on behalf of @MacroDroidDev!
 
Last edited:

sampleuserhere

Active member
I think they do, once those workarounds are compared to native function. User also doesn't have to create their own solution since those responsibility is handled by MD.

Anyway, Let's say that the end goal is to cover "general usage", then IMHO there is really no need to cover every possible corner. A function to sort or filter one dimension array with similar affinity should be sufficient for this.

Say, filter array of app names, filter array of text, sort array of number, etc.


The functions you mentioned are database-like functions, but since the concept and purpose of array/dictionary(object) are very different to databases, general programming languages also don't have such functions.

Indeed, I can't say much about other languages though. I know basic stuff in bash, like sort or unique or grep. But that's just about it.



If you really want to do some advanced processing, I'd recommend "HTTP Shortcut". Quite different from its name, it can be used as an external JavaScript interpreter(and even more powerful features are integrated) for MacroDroid.
i.e., Process the parameters sent from MD*, and then return the result** back to MD.
*: Yes, you have to invoke HTTP Shortcut twice. Once to send parameters, once to get the return value. :eek:
**: Oh, this can be done by "Intent Received" by "Wait Until Trigger", and this way'd much better. (EDITED)

I already have Tasker to do those 4 for now. MD just has to send a POST request to Tasker's local server and Tasker sends back the result as the response.

But man, In the end of the day, Those workarounds just don't sit right with me. I still prefer to have Macrodroid does all of them natively instead.
 

sampleuserhere

Active member
I don't doubt that features you suggested would be useful, but it seems hard to find the way actual implementation. If you have some detailed idea to implement # 3 as a general feature, sharing would be helpful.

Nah, there is no way I do when I deliberately sent a request here. 😂

I can do another 'workaround' with sort in shell. It supports numerical, alphabetical, and reverse order.

Check put the macro I attached below. It works against string only, would require another parsing sequences for integer.

I also still couldn't maintain "\n" value though. It always get converted into newline.
 

Attachments

  • Shell_Stunts.macro
    8.9 KB · Views: 3

Quidn

Passionate Member
I think they do, once those workarounds are compared to native function. User also doesn't have to create their own solution since those responsibility is handled by MD.
Seriously?
Except for # 3, rest are might be done by two steps - Iterate Array and an Action, as you already knew.
So you mean, using two steps of native action is too impractical and has to be avoided?
Only two steps. Two native actions. I can't agree that's difficult enough to be said like "create their own solution".


Indeed, I can't say much about other languages though. I know basic stuff in bash, like sort or unique or grep. But that's just about it.
  • Umm... grep and unique are not part of Bash...... 😰 I wonder what makes you to be sure to been "know basic stuff in bash".
  • Just for reference, Bash is not considered as a general programming language. However, It doesn't matter of course since Bash has ridiculously fewer features than any one of general programming languages.

I already have Tasker to do those 4 for now.
Again, I can't understand why you do that difficultly while except # 3 the rest could be done by only two of existing native actions.





This situation reminds me of what we discussed about the cp last time. I don't know where I start and how to say this time too.
Sorry I'm already too tired to explain everything again. I just wanted to make you realize why that woudn't be a very pratical request and I believe I already explained so much enough.
 

sampleuserhere

Active member
Lmao, that's fine dude. You don't have to correct me or explain something that I misunderstand and mistaken either. It's not even your responsibility. Even when you do, I'll be happy since I could learn something new again 😂

Well I guess you have given up, that's fine. This is just a request anyway, it doesn't have to be attended. Thanks again for the insight though 👍
 

Quidn

Passionate Member
I confused between bash and sh all the time !

⚡Pro Tip:​

  • You will never be confused if you don't distinguish them! :D

Joke but actually too I don't know about detailed differences between /([bd]?a)?sh/ and just considering all of them as POSIX-compliant shell.

I meant those are external(but preloaded) utilities, no matter what the shell is.
 
Top