Skip to content

Commit

Permalink
Extract DataRow.of()
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Nov 18, 2023
1 parent 8d154ee commit 8c947e0
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/Internal/Frame/DataRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public function __construct(array $keys, array $assoc, array $values)
$this->values = $values;
}

public static function empty(): DataRow
public static function of(array $values): DataRow
{
return new self([], [], []);
return new DataRow($values, \array_fill(0, \count($values), true), $values);
}

public static function associative($key, array $values): DataRow
public static function dictionaryEntry($key, $value): DataRow
{
return new DataRow([$key], [true], $values);
return new DataRow([$key], [true], [$value]);
}

public function isAssociative(int $index): bool
Expand All @@ -42,7 +42,6 @@ public function joined(DataRow $dataRow): DataRow
return new DataRow(
\array_merge($this->keys, $dataRow->keys),
\array_merge($this->associative, $dataRow->associative),
\array_merge($this->values, $dataRow->values)
);
\array_merge($this->values, $dataRow->values));
}
}
2 changes: 1 addition & 1 deletion src/Internal/Provider/DictionaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function dataset(): array
{
$dataset = [];
foreach ($this->dictionary as $key => $value) {
$dataset[] = DataRow::associative($key, [$value]);
$dataset[] = DataRow::dictionaryEntry($key, $value);
}
return $dataset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Provider/DistinctPairsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function dataset(): array
if ($index1 === $index2) {
continue;
}
$dataset[] = new DataRow([$augend, $addend], [true, true], [$augend, $addend]);
$dataset[] = DataRow::of([$augend, $addend]);
}
}
return $dataset;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Provider/EntriesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function dataset(): array
{
$dataset = [];
foreach ($this->dictionary as $key => $value) {
$dataset[] = new DataRow([$key, $value], [true, true], [$key, $value]);
$dataset[] = DataRow::of([$key, $value]);
}
return $dataset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Provider/ListProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function dataset(): array
{
$dataset = [];
foreach ($this->values as $value) {
$dataset[] = DataRow::associative($value, [$value]);
$dataset[] = DataRow::of([$value]);
}
return $dataset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Provider/PairsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function dataset(): array
$dataset = [];
foreach ($this->values as $augend) {
foreach ($this->values as $addend) {
$dataset[] = new DataRow([$augend, $addend], [true, true], [$augend, $addend]);
$dataset[] = DataRow::of([$augend, $addend]);
}
}
return $dataset;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Provider/TuplesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function dataset(): array
{
$dataset = [];
foreach ($this->sets as $set) {
$dataset[] = new DataRow($set, \array_fill(0, \count($set), true), $set);
$dataset[] = DataRow::of($set);
}
return $dataset;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Provider/ZipProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function count(): int

private function zippedRow(int $rowIndex): DataRow
{
$joinedRow = DataRow::empty();
$joinedRow = DataRow::of([]);
foreach ($this->dataFrames as $dataProvider) {
$joinedRow = $joinedRow->joined($dataProvider->dataset()[$rowIndex]);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Fixture/HistoryDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function arrayDatasets(): array
{
$datasets = [];
foreach ($this->elements as $key => $value) {
$datasets[] = DataRow::associative($key, [$value]);
$datasets[] = DataRow::dictionaryEntry($key, $value);
}
return $datasets;
}
Expand Down

0 comments on commit 8c947e0

Please sign in to comment.