Iterate over map?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Iterate over map?

Post by Bluscre » 13 Sep 2017 03:01

I might be stupid or too tired right now, but what was the way to iterate over a map again since for(key, value in map) doesn't work?

Code: Select all

ch.gridvision.ppam.androidautomagic.simplelang.a.d: Expression must return a collection but returned {title=com.google.android.apps.youtube.gaming:id/title, views=com.google.android.apps.youtube.gaming:id/num_views, description=com.google.android.apps.youtube.gaming:id/description, date=com.google.android.apps.youtube.gaming:id/upload_date, author=com.google.android.apps.youtube.gaming:id/channel_title, subscribers=com.google.android.apps.youtube.gaming:id/channel_subscribers} (Expression: for (k in el) {
  k = el[k]
}
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Iterate over map?

Post by Desmanto » 13 Sep 2017 07:36

What do you wanna do? You can use getMapKeys() and getMapValues() to get the keys and values to list.

Code: Select all

el = newMapFromValues(
"title","com.google.android.apps.youtube.gaming:id/title",
"view","com.google.android.apps.youtube.gaming:id/num_views", "description","com.google.android.apps.youtube.gaming:id/description", "date","com.google.android.apps.youtube.gaming:id/upload_date", "author","com.google.android.apps.youtube.gaming:id/channel_title", "subscribers","com.google.android.apps.youtube.gaming:id/channel_subscribers");

x = getMapKeys(el); // this is all the keys
y = getMapValues(el); // this is all the values 

for(i in getMapKeys(el))  //loop thru the Keys
  //do whatever to the key
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Iterate over map?

Post by Bluscre » 13 Sep 2017 20:06

So like

Code: Select all

for (k in getMapKeys(el)) {
  eval("global_"+k+" = "+el[k]);
}
?
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Iterate over map?

Post by Desmanto » 14 Sep 2017 03:19

You want to create dynamic glovar from the map? If so, use setValue()

Code: Select all

for(k in getMapKeys(el))
  setValue("global_youtube_{k}", el[k]);
I add "youtube", so those created glovar will be sorted in group.

More about dynamic GloVar
http://automagic4android.com/forum/view ... f=5&t=6813
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply