Skip to content

Conversation

@JanTvrdik
Copy link
Contributor

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
Copy link
Contributor

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

@JanTvrdik
Copy link
Contributor Author

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 master branch 2 times, most recently from 5617d88 to 209844d Compare May 21, 2015 11:51
@dg dg force-pushed the master branch 2 times, most recently from 5ed86bc to 509ef5e Compare June 19, 2015 12:53
@dg dg force-pushed the master branch 13 times, most recently from 6c03b1f to a4bddc8 Compare September 9, 2015 07:16
@dg dg force-pushed the master branch 3 times, most recently from 2998062 to f6303c6 Compare September 28, 2015 14:20
@dg
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
Copy link
Contributor Author

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
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 master branch 2 times, most recently from 46f5434 to ecbbdfc Compare December 3, 2015 12:21
@dg dg force-pushed the master branch 4 times, most recently from ae4dce9 to 3d2aa29 Compare April 21, 2016 13:00
@dg dg force-pushed the master branch 3 times, most recently from c8398ca to 47dc563 Compare September 3, 2016 12:27
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants