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

filter

The function returns a new set with things that pass the test.

This function does not generate an event.

Function

set.filter(callback)

Arguments

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

Explanation of the callback argument:

Iterable Arguments Description
set thing, Id Iterate over things in the set. Both thing and id are optional.

Return value

A new set with the things that pass the test. If no items passed the test, an empty set will be returned.

Example

This code shows an example using filter():

users = set({name: 'Iris', age: 6}, {name: 'Sasha', age: 34});

/*
 * Return all users with name 'Iris'.
 */

users.filter(|user| (user.name == 'Iris'));

Return value in JSON format

[
    {
        "age": 6,
        "name": "Iris"
    }
]