Hey @dhlewis (also, @themoatapp, what I say here will also be helpful to you):
So List Shifter, much like a custom state, is just a place to hold some list. And then, it gives you some utility functions to modify that list (e.g., reverse it, sort it, etc.) and outputs that modified list in a new location (List Shifter’s Shifted List output).
It also can be used to create entirely new lists and send them to the Processed List and/or Custom List outputs.
One thing that’s maybe spinning you is that Bubble doesn’t allow us to create arbitrary objects in the page. The only objects that Bubble has are Things (custom data types you create and are stored in the database) and (to a lesser extent) the results of API calls (which sort of look like Things, but do not have unique IDs.
So, you’re thinking about your API call results as being a list of objects with three fields (username
, a
, and b
). And then you want to construct some new object with 5 fields (username
, a
, b
, a*b
, and a*b*some_constant_c
)
Note that you can’t, in Bubble, create such an object. But you can create lists of individual data types (a list of strings/texts, a list of numbers, etc.).
So you can construct what I call parallel lists. That is, a set of lists where all the nth entry in one list corresponds to the nth entry in some other list.
So in your case you have the results of an API call with three fields that you can either store in a custom state or (perhaps) a List Shifter (see the aside below).
Aside: I don’t have an easy way to test this, but I’m not certain that List Shifter properly supports the raw response from an API get. (I realized recently that most of my plugins that deal with lists make an assumption about Things that causes them to be a little confused by lists that are API responses.) List Shifter is a little bit different because, instead of explicitly turning a Thing into its unique ID, it actually just spits the object itself out to the outputs. This isn’t documented behavior – the plugin docs suggest that Things be converted to their unique IDs – but it works and I think the same goes for API responses, but FYI, that you might have to store the results of an in-page API call to a custom state if you find that List Shifter doesn’t do it right.
Anyway, having your API response (stored in a custom state or in a List Shifter - let’s call it LS API
), you can have additional List Shifters that hold the decomposed values. That is, a List Shifter of type text to hold usernames (set its source to be something like LS API's Original List's each items username
) . And similarly you can have List Shifters of type number (let’s call them List Shifter A
and List Shifter B
) for a and b – set their sources like LS API's Original List's each item's a
/ LS API's Original List's each item's b
.
And then to compute your a*b,
you would use the PROCESS List action. You can trigger that action when List Shifter B
is initialized/updated. You’d set that up like this:
What this says is, "for each item in List Shifter B, multiply it by the corresponding Item in “LS Type List Constant”. And we push each computed value on to the Processed List by setting this option:
LS Type List Constant
is provided by a field in the PROCESS List dialog, which appears way down at the bottom. (“LS Type List” means, “a list of the same type as this List Shifter”).
You’d set that up as being List Shifter A’s Original List, like so:
And so when this runs, List Shifter B’s Processed List now contains the results of a*b.
We could further set up another List Shifter to compute each item a*b times some constant c. The smart way to do this is to create a List Shifter C which takes List B’s Processed List as its list source (“List to Shift”), and imports the constant C via the Use Scalar input:
Such a List Shifter will Initialize/Update whenever either value changes. So we can set up a PROCESS List action on List Shifter C that fires whenever it updates, like so:
And when this runs, List Shifter C’s Processed List will contain the values of a*b*c
. (And it will automagically recompute should the list of a*b or constant c change.
And now you can visualize your results either as text or in a Repeating Group, as shown in the demo below.
Here’s a simple example, where instead of lists “a” and “b” coming from a API call, they are just lists of numbers generated by List Shifter itself:
Run mode: https://list-shifter-demo.bubbleapps.io/version-test/listwise_multiply?debug_mode=true
Edit mode: List-shifter-demo | Bubble Editor