This is the ThingsDB documentation for version v0, click here for the latest version!

map

The function iterates over all properties on a thing and returns a new list based on the results of a given callback function.

Be aware that the order when iterating over a thing is not guaranteed.

This function does not generate an event.

Function

thing.map(callback)

Arguments

Argument Type Description
callback closure (required) Closure to execute on each value.

Explanation of the callback argument:

Iterable Arguments Description
thing name, value Iterate over the thing properties. Both name and value are optional.

Return value

A new list of items that are the result of the callback function.

Example

This code shows an example using map():

user = {name: "Iris", age: 6};

user.map(|property| property.len());

Return value in JSON format

[
    4,
    3
]