Comments (4)
@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.
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.
@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.
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)
- BinarySuffix Division by zero
- Symfony4 support HOT 1
- Update Composer to support later version of Symfony 4.2 HOT 1
- Support for English formats HOT 1
- Psr-4 autoloading standard HOT 2
- transChoice is removed as of symfony / translation:5.0 HOT 2
- compatibility with symfony 5 HOT 2
- Decret
- Make installable for L9 HOT 1
- The Symfony\Polyfill\Intl\Icu\NumberFormatter::__construct() method's argument $style value 0 behavior is not implemented HOT 1
- Support for different character separators HOT 4
- Support for IEC standard prefixes and suffix translation HOT 5
- Number::binarySuffix() throws exception when intl extension is missing HOT 3
- PHP 7 release HOT 6
- Translation error HOT 1
- Division by zero HOT 6
- Problem with big numbers HOT 2
- Failed to try to calculate difference between dates and times equal
- Bug: uncaught InvalidArgumentException in CollectionHumanizer::oxford with correct input HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-humanizer.