HomeDevCentral

Allow to map hashmap into a vector
95fdbfcfe7d9Unpublished

Unpublished Commit · Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.
This commit has been deleted in the repository: it is no longer reachable from any branch, tag, or ref.

Description

Allow to map hashmap into a vector

Summary:
HashMap::mapToVector allows to build a vector from an hashmap.

In Rust, an iterator can be mapped into any type, the outcome
of the iteration is decided afterwards by a collect method.

In PHP, native functions like array_map preserves the initial type.
As such, HashMap::map returns an HashMap.

The mapToVector method allows to collect the mapped values into a vector.

Test Plan:
This is intended for Zed to be used with API string representation:

$response = HashMap::from($data)
    ->mapToVector(
        fn($key, $value) => "$key: " . self::toString($value)
    )
    ->implode(", ");

Unit tests are provided for our the different callback shapes.

Reviewers: dereckson

Reviewed By: dereckson

Differential Revision: https://devcentral.nasqueron.org/D3214

Details

Provenance
derecksonAuthored on Jun 30 2023, 21:36
derecksonPushed on Jul 1 2023, 20:39
Parents
rKERUALD8b319b6a4193: Provide reflection bricks to build a service container
Branches
Unknown
Tags
Unknown

Event Timeline