yiisoft / yii2-collection

Collection extension for Yii 2
BSD 3-Clause "New" or "Revised" License
67 stars 19 forks source link

Idea: Fluent interface #9

Open SamMousa opened 7 years ago

SamMousa commented 7 years ago

The current implementation of GeneratorCollection supports functions like filter and map.

Doing something like I've proposed here: https://github.com/nikic/iter/issues/45 Would allow for a fluent interface allowing code like

$collection->filter(...)->map(....)->...
cebe commented 7 years ago

I was looking for a way to make GeneratorCollection a fluent interface, but did not find a good way yet, as it is returning a generator via yield. Thanks for the suggestion, will look into that.

sjelfull commented 7 years ago

I think the gold standard for collections is Laravel Collections, which have been working great for me.

Probably a good idea to use that as inspiration.

vanodevium commented 6 years ago

Framework agnostic laravel collections

SamMousa commented 6 years ago

They are not iterables though, so each operation duplicates memory usage (I think after a quick check from my phone)

masihfathi commented 6 years ago

i have a question, dose chaining mathod in this way and the way laravel does for collections now is the right way? because i think chaining method this way make extra loop in a chain of methods and mayby decrease performance, and mayby cause some impure functions as i see in other places like in some functions of ruby lang in a chain of functions on an object.

cebe commented 6 years ago

GeneratorCollection currently uses yield which does not allow method chaining. Collection allows method chaining but is not efficient as it may do multiple cycles over an array. The purpose of this issue is to evaluate ways to enable method chaning with generators.