flip()

Flip operator iterates over given stream of iterables and yields each item with keys and values flipped. This operator is useful when you want to invert the keys and values of a dataset.

class RunOpenCode\Component\Dataset\Operator\Flip
__construct(iterable<TKey, TValue> $source)
Parameters:
  • $source – iterable<TKey, TValue> Stream of items to iterate over.

getIterator()
Returns:

\Traversable<TValue, TKey> Flipped stream.

Use cases

  • Use this operator to flip keys and values of a dataset.

Example

1<?php
2
3use RunOpenCode\Component\Dataset\Stream;
4
5new Stream($dataset)
6    ->flip(); // yields value => key instead of key => value.