Giter Club home page Giter Club logo

Comments (4)

cyrillkalita avatar cyrillkalita commented on September 2, 2024 1

@norberttech i think i know what @gabrielanhaia means:

Right now if I want to oxford something, i must do:

$collection = collect(['Eneh', 'Beneh', 'Rabba', 'Clatu',' Verata', 'Nictu']);

Coduo\PHPHumanizer\CollectionHumanizer::oxford($collection->toArray(), 3)

and it would be swell if we can just pass a collection

from php-humanizer.

norberttech avatar norberttech commented on September 2, 2024

Hey, I'm honestly not sure if I fully understand the problem that \Iterator would solve here. Could you maybe come up with some pseudo code example to help me visualize it?

from php-humanizer.

gabrielanhaia avatar gabrielanhaia commented on September 2, 2024

@cyrillkalita is correct.

I would say that \Traversable interface would be an even better option.
We could even do things like:

class CustomCollection implements \Traversable
{...}
...
function listWithGenerator(array $array): \Generator
{
    foreach ($array as $x) {
           //... Do something here
           //... 
           yield $x;
    }
}

all of the above options would work:

$collection = new CustomCollection(['Eneh', 'Beneh', 'Rabba', 'Clatu',' Verata', 'Nictu']);
$collection2 = collect(['Eneh', 'Beneh', 'Rabba', 'Clatu',' Verata', 'Nictu']);
$array = ['Eneh', 'Beneh', 'Rabba', 'Clatu',' Verata', 'Nictu'];
$generators = $this->listWithGenerator(['Eneh', 'Beneh', 'Rabba', 'Clatu',' Verata', 'Nictu']);


Coduo\PHPHumanizer\CollectionHumanizer::oxford($collection, 3);
Coduo\PHPHumanizer\CollectionHumanizer::oxford($collection2, 3);
Coduo\PHPHumanizer\CollectionHumanizer::oxford($array, 3);
Coduo\PHPHumanizer\CollectionHumanizer::oxford($generators, 3);

from php-humanizer.

norberttech avatar norberttech commented on September 2, 2024

The prosed change is too big BC break compared to the benefits in my opinion.

- public static function oxford(array $collection, int $limit = null, string $locale = 'en') : string
+ public static function oxford(\Traversable $collection, int $limit = null, string $locale = 'en') : string

However:

-   public static function oxford(array $collection, int $limit = null, string $locale = 'en') : string
+   public static function oxford(iterable $collection, int $limit = null, string $locale = 'en') : string
    {
        $oxford = new Oxford(
            new Formatter(Builder::build($locale))
        );

-       return $oxford->format($collection, $limit);
+       return $oxford->format((array) $collection, $limit);
    }

Should be fine, iterable pseud type will support both, array and \Traversable so it does not seem to be a BC break.

from php-humanizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.