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

Allow mappers to use NULL keys for appending to the result #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thekid
Copy link
Member

@thekid thekid commented Mar 17, 2023

By using an explicit null in yield we can append to the result instead.

Note: Unfortunately, we cannot distinguish yield $value and yield 0 => $value from each other at runtime, or else we would've used the short form for this behaviour, while interpreting the one with the explicit 0 as setting $result[0].

Example

$opcodes= function() {
  yield 'const'    => 1;
  yield 'add'      => 1;
  yield 'multiply' => 2;
  yield 'add'      => -1;
};
$a= (new Assertable($opcodes()))->mappedBy(function($arg, $op) { yield null => [$op, $arg]; });
$a->value; // [['const', 1], ['add', 1], ['multiply', 2], ['add', -1]]

@thekid thekid added the enhancement New feature or request label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant