Page MenuHomeDevCentral

Allow to map hashmap into a vector
ClosedPublic

Authored by dereckson on Jun 30 2023, 21:43.
Tags
None
Referenced Files
F56062093: D3214.id8231.diff
Mon, Nov 2, 11:54
F56062078: D3214.id8230.diff
Mon, Nov 2, 11:54
F56062067: D3214.id.diff
Mon, Nov 2, 11:54
Unknown Object (File)
Sat, Oct 31, 00:24
Unknown Object (File)
Fri, Oct 30, 16:47
Unknown Object (File)
Wed, Oct 28, 15:19
Unknown Object (File)
Sat, Oct 24, 17:49
Unknown Object (File)
Sat, Oct 17, 23:22
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 Not Applicable
Unit
Tests Not Applicable