Skip to content

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.

2 participants