Page MenuHomeDevCentral

Allow to map hashmap into a vector
ClosedPublic

Authored by dereckson on Jun 30 2023, 21:43.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Mar 10, 21:34
Unknown Object (File)
Mon, Mar 3, 03:16
Unknown Object (File)
Mon, Mar 3, 03:00
Unknown Object (File)
Fri, Feb 28, 15:56
Unknown Object (File)
Sun, Feb 16, 15:50
Unknown Object (File)
Sun, Feb 16, 15:32
Unknown Object (File)
Feb 10 2025, 00:22
Unknown Object (File)
Feb 5 2025, 20:30
Subscribers
None

Details

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.

Diff Detail

Repository
rKERUALD Keruald libraries development repository
Lint
Lint Passed
Unit
Tests Passed
Branch
map-to-vector
Build Status
Buildable 5065
Build 5346: arc lint + arc unit