lstrojny / functional-php

Primitives for functional programming in PHP
MIT License
1.98k stars 204 forks source link

Make these functions more expressive #220

Closed videni closed 4 years ago

videni commented 4 years ago

current we have to do something like this.

map(
    filter($fields, function($field){
        return 'user' != $field->fieldTypeIdentifier;
    }), 
    function($field){
        return [
            $field->fieldDefIdentifier => $field->value
        ];
    }
)

A better approach.

filter($fields, function($field){
    return 'ezuser' != $field->fieldTypeIdentifier;
})->map(function($field){
    return [
        $field->fieldDefIdentifier => $field->value
    ];
})
tzkmx commented 4 years ago

This would require returning objects to chain methods, reminds me of Collection class of Illuminate (Laravel), as another consumer of this package, I don't get what enhancement that would give, but is clearly a lot of effort to implement.

lstrojny commented 4 years ago

I don’t plan to change the API towards a collection API in the future

drupol commented 3 years ago

@videni maybe this project would help you ? https://github.com/loophp/collection

Feel free to let me know if my comment is not welcome and I'll delete it straight.

Keep up the good work.