"Pick" function

It would be nice to have a function, called pick, to transform a list of Thing to a list of Field, where Field is a field of Thing.
The syntax would be like in the following example:
Search for User:pick(name)
So, given a list of User, each of them with a text field called “name”, this list could be transformed to a list of text.

If I’m understanding correctly, you can already do this by writing “Search for User’s Name” and that would result in a comma separated list of texts (i.e. the list of names). Try it with a text element or a repeating group that’s set to data type = text; each cell would be a separate text.

1 Like

I’ve written my post too quickly and it doesn’t make sense.

You’re absolutely right, we can already pick a field in Bubble.

What I forgot to add is that pick can take a field or an expression as an argument, so that we could do things like
Search for User: pick(ratings:sorted:first item)'s vote where User has a list of Rating (a Thing with a number called vote and a date) and we want to pick the latest rating for each user.

I can’t envision how to do that at the moment without a pick function (which actually looks like the map function)

@furnys if you’re displaying the data in a repeating group then you can easily do what you asked.
Note that repeating group will allow you to apply a certain function to each element of your list (cell) mimicking a map function.

So you could have a repeating group whose type is User and data source is Search for User.
Then to get the most recent vote of each user from their list of ratings you simply do the following expression.

I’m using the default Modified Date field for the date. You an use any date field.
Below is an example. The top table shows the users with their list of ratings (vote and date)
The bottom shows the latest (look at the times) votes for each user.

That’s true, but I would be required to use a visual element (the Repeating Group).
It wouldn’t work in an API Workflow, because it wouldn’t be possible to create a Repeating Group.

If you iterate on the user list, you can perform that extraction for each User independently. You can do this either with “Schedule an API Workflow on a List” or running an API workflow recursively.

The API Endpoint would need a parameter for “User” so that you can use the expression:

User’s ratings :sorted (by date) :first item’s vote

And then I could build the results list by passing it to each API Workflow, which extracts the element and adds it to the shared results list.
That would work, assuming that the list is mutable and passed by reference (not by value).