Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generators barf bag #81

Open
nozavroni opened this issue Jan 20, 2017 · 0 comments
Open

Generators barf bag #81

nozavroni opened this issue Jan 20, 2017 · 0 comments
Assignees
Labels

Comments

@nozavroni
Copy link
Owner

nozavroni commented Jan 20, 2017

This issue will just be a place for me to barf ideas about how best to utilize generators within this library.

So far this library doesn't make use of generators whatsoever, which is really a shame. I think it's time we introduce generators somehow. I have a few ideas for this...

Generator Collection Decorator

$coll = new Collection(['blba','babas','asdsad','bleeebloo',3,4,5,6]);
$gencoll = new GeneratorDecorator($coll);
// now $gencoll can be used exactly as you would use $coll, only now its values are yielded

But no that wouldn't work because generators can only go one way (and they can only be looped over once). So what would be a more appropriate use for generators here? Well there's this: #80.

Another good use of generators would be for things like #46. When doing things like this:

$coll = CollectionFactory::fromGenerator(function() {
    foreach (range(1,20) as $val) {
        yield $val;
    }
});
// or... 
$coll = MySQLFactory::fromQuery($sql);
@nozavroni nozavroni self-assigned this Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant