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

Arrays: added functional API #36

Closed
wants to merge 1 commit into from
Closed

Conversation

@JanTvrdik
Copy link
Contributor

JanTvrdik commented Nov 2, 2014

I love those methody in JS, would be nice to have them in PHP as well. What do you think?

@JanTvrdik JanTvrdik changed the title WIP: Arrays: added functional API Arrays: added functional API Nov 2, 2014
@fprochazka

This comment has been minimized.

Copy link
Contributor

fprochazka commented Nov 2, 2014

Nice methods. I think we should revisit the idea of wrapping the scalars/arrays in objects.

@JanTvrdik

This comment has been minimized.

Copy link
Contributor Author

JanTvrdik commented Nov 2, 2014

I think we should revisit the idea of wrapping the scalars/arrays in objects.

That makes very little sense if not supported by language. Wait for PHP 7.

@dg dg force-pushed the nette:master branch 2 times, most recently from 5617d88 to 209844d May 21, 2015
@dg dg force-pushed the nette:master branch 2 times, most recently from 5ed86bc to 509ef5e Jun 17, 2015
@dg dg force-pushed the nette:master branch 13 times, most recently from 6c03b1f to a4bddc8 Sep 3, 2015
@dg dg force-pushed the nette:master branch 3 times, most recently from 2998062 to f6303c6 Sep 26, 2015
@dg

This comment has been minimized.

Copy link
Member

dg commented Oct 19, 2015

Now it (i.e. map of filter) can be implemented using generators:

class Iterators
{
    public static function map($iterator, callable $callback)
    {
        foreach ($iterator as $key => $value) {
            yield $key => $callback($value);
        }
    }

    public static function filter($iterator, callable $callback)
    {
        foreach ($iterator as $key => $value) {
            if ($callback($value)) {
                yield $key => $value;
            }
        }
    }
@JanTvrdik

This comment has been minimized.

Copy link
Contributor Author

JanTvrdik commented Oct 19, 2015

Yes. But I would expect map to return array if I pass array as argument. Using generators when Traversable is passed should be OK.

@enumag

This comment has been minimized.

Copy link
Contributor

enumag commented Oct 20, 2015

@dg Generators are good but I don't think we need functions like this in Nette. Just use nikic/iter.

@dg dg force-pushed the nette:master branch 2 times, most recently from 46f5434 to ecbbdfc Dec 3, 2015
@dg dg force-pushed the nette:master branch from ffe0d72 to ded23a7 Apr 21, 2016
@dg dg force-pushed the nette:master branch 4 times, most recently from ae4dce9 to 3d2aa29 Apr 21, 2016
@dg dg force-pushed the nette:master branch 3 times, most recently from c8398ca to 47dc563 Sep 3, 2016
@dg dg closed this in bff1080 Dec 19, 2016
dg added a commit that referenced this pull request Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.