Simpler isContainer()

by Ricardo “Rudxain” Fernández Serrata

Version 1 (April 28, 2024)

Download (161 downloads)

Better than `type(x) = "array" || type(x) = "dictionary"`

This exploits the fact that `type(x)` always ends with "y" when `x` isn't primitive, and the fact that the AM flow interpreter is kinda bad at optimizing code.

The expression I used is equal to `substr(type(x), -1, 1) = "y"`, but the subscript operator and number comparison are faster to process and shorter to write than substr() with string comparison. The downside is that the short version is less readable on 1st sight.

If you want more speed, use 0x79 instead of 121. I was very surprised when I did benchmarks and the hex literal made another flow faster, so maybe it could be faster here too (this will change in future AM versions, so there's no need to follow this "advice")

LICENSE: https://unlicense.org

Rudxain profile: llamalab.com/automate/community/flows/42921

4.8 average rating from 5 reviews

5 stars
4
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.