Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sequences instead of sets #13

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/Adapter/Filesystem/Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Innmind\Immutable\{
Maybe,
Set,
Sequence,
Predicate\Instance,
};

Expand Down Expand Up @@ -67,8 +68,7 @@ public function __invoke(Aggregate\Id $id = null): callable
->map(static fn($file) => Aggregate\Property::of(
$file->name()->toString(),
Json::decode($file->content()->toString()),
))
->toSet(),
)),
),
$directory
->get(Name::of('entities'))
Expand All @@ -86,11 +86,9 @@ public function __invoke(Aggregate\Id $id = null): callable
->map(static fn($property) => Aggregate\Property::of(
$property->name()->toString(),
Json::decode($property->content()->toString()),
))
->toSet(),
)),
),
)
->toSet(),
),
),
$directory
->get(Name::of('optionals'))
Expand All @@ -112,12 +110,10 @@ public function __invoke(Aggregate\Id $id = null): callable
->map(static fn($property) => Aggregate\Property::of(
$property->name()->toString(),
Json::decode($property->content()->toString()),
))
->toSet(),
)),
),
),
)
->toSet(),
),
),
$directory
->get(Name::of('collections'))
Expand All @@ -132,7 +128,7 @@ public function __invoke(Aggregate\Id $id = null): callable
Set::of(...Json::decode($collection->content()->toString()))->map(
static fn($entity) => Aggregate\Collection\Entity::of(
Reference::of($entity['reference']),
Set::of(...$entity['properties'])->map(
Sequence::of(...$entity['properties'])->map(
static fn($property) => Aggregate\Property::of(
$property[0],
$property[1],
Expand All @@ -141,10 +137,9 @@ public function __invoke(Aggregate\Id $id = null): callable
),
),
),
)
->toSet(),
),
),
)->map(static fn(Set $properties, Set $entities, Set $optionals, Set $collections) => Aggregate::of(
)->map(static fn(Sequence $properties, Sequence $entities, Sequence $optionals, Sequence $collections) => Aggregate::of(
$id($directory),
$properties,
$entities,
Expand Down
12 changes: 6 additions & 6 deletions src/Adapter/SQL/CollectionTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class CollectionTable
/** @var Definition<T> */
private Definition $definition;
private Table\Name\Aliased $name;
/** @var Set<Column\Name\Aliased> */
private Set $columns;
/** @var Sequence<Column\Name\Aliased> */
private Sequence $columns;
private Column\Name\Namespaced $id;
private Column\Name\Namespaced $reference;
private Select $select;
Expand Down Expand Up @@ -98,9 +98,9 @@ public function foreignKey(): Table\Column
}

/**
* @return Set<Column>
* @return Sequence<Column>
*/
public function columnsDefinition(MapType $mapType): Set
public function columnsDefinition(MapType $mapType): Sequence
{
return $this
->definition
Expand All @@ -117,9 +117,9 @@ public function name(): Table\Name\Aliased
}

/**
* @return Set<Column\Name\Aliased>
* @return Sequence<Column\Name\Aliased>
*/
public function columns(): Set
public function columns(): Sequence
{
return $this->columns;
}
Expand Down
13 changes: 6 additions & 7 deletions src/Adapter/SQL/Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Innmind\Immutable\{
Maybe,
Set,
Sequence,
Str,
};

Expand Down Expand Up @@ -77,8 +78,7 @@ public function __invoke(Aggregate\Id $id = null): callable
->map(static fn($value) => Aggregate\Property::of(
Str::of($value->column()->toString())->drop(7)->toString(),
$value->value(),
))
->toSet(),
)),
$this
->mainTable
->entities()
Expand Down Expand Up @@ -154,11 +154,11 @@ public static function of(
/**
* @psalm-pure
*
* @param Set<Column\Name\Aliased> $columns
* @param Sequence<Column\Name\Aliased> $columns
*
* @return Set<Aggregate\Property>
* @return Sequence<Aggregate\Property>
*/
private static function properties(Row $row, Set $columns): Set
private static function properties(Row $row, Sequence $columns): Sequence
{
/** @psalm-suppress MixedArgument Due to the access-layer type */
return $columns->flatMap(
Expand All @@ -171,8 +171,7 @@ private static function properties(Row $row, Set $columns): Set
},
$value,
))
->toSequence()
->toSet(),
->toSequence(),
);
}
}
36 changes: 14 additions & 22 deletions src/Adapter/SQL/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
Raw\Aggregate,
};
use Formal\AccessLayer\Query;
use Innmind\Immutable\{
Set,
Sequence,
};
use Innmind\Immutable\Sequence;

/**
* @internal
Expand Down Expand Up @@ -47,12 +44,10 @@ public function __invoke(Aggregate $data): Sequence
$optionals = $this->optionals($data);
$collections = $this->collections($data);

return Sequence::of(
$main,
...$entities->toList(),
...$optionals->toList(),
...$collections->toList(),
);
return Sequence::of($main)
->append($entities)
->append($optionals)
->append($collections);
}

/**
Expand All @@ -73,9 +68,9 @@ public static function of(
}

/**
* @return Set<Query>
* @return Sequence<Query>
*/
private function entities(Aggregate $data): Set
private function entities(Aggregate $data): Sequence
{
return $data
->entities()
Expand All @@ -86,15 +81,14 @@ private function entities(Aggregate $data): Set
->map(
static fn($table) => $table->insert($data->id(), $entity->properties()),
)
->toSequence()
->toSet(),
->toSequence(),
);
}

/**
* @return Set<Query>
* @return Sequence<Query>
*/
private function optionals(Aggregate $data): Set
private function optionals(Aggregate $data): Sequence
{
return $data
->optionals()
Expand All @@ -107,8 +101,7 @@ private function optionals(Aggregate $data): Set
static fn($properties) => $table->insert($data->id(), $properties),
),
)
->toSequence()
->toSet(),
->toSequence(),
);
}

Expand All @@ -121,9 +114,9 @@ private function main(Aggregate $data): Query
}

/**
* @return Set<Query>
* @return Sequence<Query>
*/
private function collections(Aggregate $data): Set
private function collections(Aggregate $data): Sequence
{
return $data
->collections()
Expand All @@ -137,8 +130,7 @@ private function collections(Aggregate $data): Set
$collection->entities(),
),
)
->toSequence()
->toSet(),
->toSequence(),
);
}
}
22 changes: 11 additions & 11 deletions src/Adapter/SQL/EntityTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
};
use Innmind\Specification\Sign;
use Innmind\Immutable\{
Set,
Sequence,
Maybe,
};

Expand All @@ -31,8 +31,8 @@ final class EntityTable
/** @var Definition<T> */
private Definition $definition;
private Table\Name\Aliased $name;
/** @var Set<Column\Name\Aliased> */
private Set $columns;
/** @var Sequence<Column\Name\Aliased> */
private Sequence $columns;

/**
* @param Definition<T> $definition
Expand Down Expand Up @@ -77,9 +77,9 @@ public function primaryKey(): Table\Column
}

/**
* @return Set<Column>
* @return Sequence<Column>
*/
public function columnsDefinition(MapType $mapType): Set
public function columnsDefinition(MapType $mapType): Sequence
{
return $this
->definition
Expand All @@ -96,19 +96,19 @@ public function name(): Table\Name\Aliased
}

/**
* @return Set<Column\Name\Aliased>
* @return Sequence<Column\Name\Aliased>
*/
public function columns(): Set
public function columns(): Sequence
{
return $this->columns;
}

/**
* @internal
*
* @param Set<Property> $properties
* @param Sequence<Property> $properties
*/
public function insert(Id $id, Set $properties): Query
public function insert(Id $id, Sequence $properties): Query
{
$table = $this->name->name();

Expand All @@ -132,11 +132,11 @@ public function insert(Id $id, Set $properties): Query
/**
* @internal
*
* @param Set<Property> $properties
* @param Sequence<Property> $properties
*
* @return Maybe<Query>
*/
public function update(Id $id, Set $properties): Maybe
public function update(Id $id, Sequence $properties): Maybe
{
return Maybe::just($properties)
->filter(static fn($properties) => !$properties->empty())
Expand Down
29 changes: 14 additions & 15 deletions src/Adapter/SQL/MainTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use Innmind\Immutable\{
Map,
Maybe,
Set,
Sequence,
};

/**
Expand Down Expand Up @@ -114,7 +114,6 @@ private function __construct(Definition $definition)
->toList(),
...$entities
->values()
->toSet()
->flatMap(static fn($table) => $table->columns())
->toList(),
);
Expand Down Expand Up @@ -161,9 +160,9 @@ public function primaryKey(): Table\Column
}

/**
* @return Set<Column>
* @return Sequence<Column>
*/
public function columnsDefinition(MapType $mapType): Set
public function columnsDefinition(MapType $mapType): Sequence
{
return $this
->definition
Expand Down Expand Up @@ -212,11 +211,11 @@ public function count(Specification $specification = null): Select
/**
* @internal
*
* @param Set<Aggregate\Property> $properties
* @param Sequence<Aggregate\Property> $properties
*/
public function insert(
Id $id,
Set $properties,
Sequence $properties,
): Query {
$table = $this->name->name();

Expand Down Expand Up @@ -276,11 +275,11 @@ public function delete(): Delete
}

/**
* @return Set<EntityTable>
* @return Sequence<EntityTable>
*/
public function entities(): Set
public function entities(): Sequence
{
return $this->entities->values()->toSet();
return $this->entities->values();
}

/**
Expand All @@ -294,11 +293,11 @@ public function entity(string $name): Maybe
}

/**
* @return Set<OptionalTable>
* @return Sequence<OptionalTable>
*/
public function optionals(): Set
public function optionals(): Sequence
{
return $this->optionals->values()->toSet();
return $this->optionals->values();
}

/**
Expand All @@ -312,11 +311,11 @@ public function optional(string $name): Maybe
}

/**
* @return Set<CollectionTable>
* @return Sequence<CollectionTable>
*/
public function collections(): Set
public function collections(): Sequence
{
return $this->collections->values()->toSet();
return $this->collections->values();
}

/**
Expand Down
Loading
Loading