lstrojny / functional-php

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

Proposal: Add compact() #232

Closed phanan closed 3 years ago

phanan commented 3 years ago

WDYT about adding a Functional\compact() function that removes all falsy values from a collection à la lodash? It can be named something like compress() as well if there's any concern regarding the existing compact() in PHP. I can give it a try.

lstrojny commented 3 years ago

select([0, false, 1]) should do that already as the default callback is the identity function, no?

phanan commented 3 years ago

Yeah, as so should array_filter and the likes, but I'd argue a dedicated function is better, even if its internal implementation is exactly the same.

lstrojny commented 3 years ago

That’s a too limited purpose in my mind that it would warrant an additional function. Let’s not add it! 😄