Anemone::map()

Creates a new data set from the current data.

Table of Contents
  1. Description
  2. Example

Description

Anemone::map(callable $fn): Anemone;

This is the OOP style of function map(), implemented as a class method. It creates a new data set populated with the results of calling a provided function on every item in the data. This method returns new Anemone instance.

Example

$anemone = new Anemone([1, 2, 3, 4, 5]);

$test = $anemone->map(function ($v, $k) {
    return ($k + 2) . ': ' . $v;
});

test($test->get()); // Returns `['2: 1', '3: 2', '4: 3', '5: 4', '6: 5']`
test($test === $anemone); // Returns `false`
test($test->parent === $anemone); // Returns `true`

You call the Anemone::get() method to return raw array values, but you can also directly iterate over it.

Anemone::any()

Checks if at least one item in the data passes the test.

Anemone::is()

Filters the data so that only items that pass the test are left.

Anemone::map()

Creates a new data set from the current data.

Anemone::not()

Filters the data so that only items that do not pass the test are left.

Anemone::pluck()

Returns a new data set contains values from the key on every item.