Returns the values mapped by the supplied function and then flattens
the values into a single traversable. Keys will be reindexed.
public selectMany ( callable $function ) : pinq\ITraversable | ||
$function | callable | The function returning the data to select |
Результат | pinq\ITraversable |
/** * @dataProvider tenRandomStrings */ public function testThatSelectManyFlattensCorrectlyAndIgnoresKeys(\Pinq\ITraversable $values, array $data) { $characters = $values->selectMany(function ($i) { return str_split($i); }); $this->assertMatches($characters, array_values(self::flattenArrays(array_map('str_split', $data)))); }
/** * @dataProvider someStrings */ public function testSelectManyQuery(\Pinq\ITraversable $traversable, array $data) { foreach ($traversable->selectMany(function ($i) { return str_split($i); })->getTrueIterator() as $value) { } $string = $traversable->selectMany(function ($i) { return str_split($i); })->select(function ($char) { return $char; })->implode(''); $trueString = ''; foreach ($data as $i) { foreach (str_split($i) as $char) { $trueString .= $char; } } $this->assertEquals($trueString, $string); }
public function visitSelectMany(Segments\SelectMany $query) { $this->traversable = $this->traversable->selectMany($this->resolvedParameters[$query->getProjectionFunction()->getCallableId()]); }