⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

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

Open
thekid wants to merge 2 commits intomainfrom
feature/mappedBy-append
Open

Allow mappers to use NULL keys for appending to the result#18
thekid wants to merge 2 commits intomainfrom
feature/mappedBy-append

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