-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allow object keys #24
Conversation
Codecov Report
@@ Coverage Diff @@
## 2.0.x-dev #24 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 2 2
Lines 43 43
===========================================
Hits 43 43
Continue to review full report at Codecov.
|
Yeah, definitely 🙂 |
So I can edit other functions too. However, this restricts only one read of output iterable as the value is of type Generator I'm used to it as I use generators extensively but don't have overview out of my bubble. |
Indeed, forgot that. I have a fix in mind. |
Well, here's the fix I was thinking about: function iterable_map(iterable $iterable, callable $map): iterable
{
return new class ($iterable, $map) implements IteratorAggregate {
private $iterable;
private $map;
public function __construct(iterable $iterable, callable $map)
{
$this->iterable = $iterable;
$this->map = $map;
}
public function getIterator(): Traversable
{
foreach ($this->iterable as $key => $item) {
yield $key => ($this->map)($item);
}
}
};
} It works, but basically this anonymous class is exactly what What we could do is a refactoring, where functions would just be shortcuts to function iterable_map(iterable $iterable, callable $map): iterable
{
return iterable($iterable)->map($map);
} WDYT? |
Ah yes, we simply have to leverage IteratorAggregate and we're good to go. |
OK, I will perform the refactoring as soon as #25 is merged. |
WDYT about this? Currently only
array-key
is supported as key type for all functions.