Skip to content

Commit

Permalink
use sequences instead of sets
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Feb 11, 2024
1 parent f9275d5 commit c98dbcd
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 202 deletions.
15 changes: 6 additions & 9 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 @@ -89,8 +89,7 @@ public function __invoke(Aggregate\Id $id = null): callable
))
->toSet(),
),
)
->toSet(),
),
),
$directory
->get(Name::of('optionals'))
Expand All @@ -116,8 +115,7 @@ public function __invoke(Aggregate\Id $id = null): callable
->toSet(),
),
),
)
->toSet(),
),
),
$directory
->get(Name::of('collections'))
Expand All @@ -141,10 +139,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
3 changes: 1 addition & 2 deletions src/Adapter/SQL/Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,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
31 changes: 13 additions & 18 deletions src/Adapter/SQL/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,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 +71,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 +84,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 +104,7 @@ private function optionals(Aggregate $data): Set
static fn($properties) => $table->insert($data->id(), $properties),
),
)
->toSequence()
->toSet(),
->toSequence(),
);
}

Expand All @@ -121,9 +117,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 +133,7 @@ private function collections(Aggregate $data): Set
$collection->entities(),
),
)
->toSequence()
->toSet(),
->toSequence(),
);
}
}
27 changes: 14 additions & 13 deletions src/Adapter/SQL/MainTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
Map,
Maybe,
Set,
Sequence,
};

/**
Expand Down Expand Up @@ -161,9 +162,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 +213,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 +277,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 +295,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 +313,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
20 changes: 8 additions & 12 deletions src/Adapter/SQL/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public function __invoke(Diff $data): Sequence
)
->toSequence(),
)
->toSequence()
->toSet(),
->toSequence(),
);
$optionals = $data
->optionals()
Expand All @@ -58,8 +57,7 @@ public function __invoke(Diff $data): Sequence
$data->id(),
$optional,
))
->toSequence()
->toSet(),
->toSequence(),
);
$collections = $data
->collections()
Expand All @@ -74,16 +72,14 @@ public function __invoke(Diff $data): Sequence
static fn($entity) => $entity->reference(),
),
))
->toSequence()
->toSet(),
->toSequence(),
);

return Sequence::of(
$main,
...$entities->toList(),
...$optionals->toList(),
...$collections->toList(),
)->flatMap(static fn($queries) => $queries);
return Sequence::of($main)
->append($entities)
->append($optionals)
->append($collections)
->flatMap(static fn($queries) => $queries);
}

/**
Expand Down
50 changes: 25 additions & 25 deletions src/Definition/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Innmind\Reflection\ReflectionClass;
use Innmind\Immutable\{
Str,
Set,
Sequence,
Monoid\Concat,
};

Expand All @@ -21,30 +21,30 @@ final class Aggregate
private string $class;
/** @var Aggregate\Identity<T> */
private Aggregate\Identity $id;
/** @var Set<Aggregate\Property<T, mixed>> */
private Set $properties;
/** @var Set<Aggregate\Entity> */
private Set $entities;
/** @var Set<Aggregate\Optional> */
private Set $optionals;
/** @var Set<Aggregate\Collection> */
private Set $collections;
/** @var Sequence<Aggregate\Property<T, mixed>> */
private Sequence $properties;
/** @var Sequence<Aggregate\Entity> */
private Sequence $entities;
/** @var Sequence<Aggregate\Optional> */
private Sequence $optionals;
/** @var Sequence<Aggregate\Collection> */
private Sequence $collections;

/**
* @param class-string<T> $class
* @param Aggregate\Identity<T> $id
* @param Set<Aggregate\Property<T, mixed>> $properties
* @param Set<Aggregate\Entity> $entities
* @param Set<Aggregate\Optional> $optionals
* @param Set<Aggregate\Collection> $collections
* @param Sequence<Aggregate\Property<T, mixed>> $properties
* @param Sequence<Aggregate\Entity> $entities
* @param Sequence<Aggregate\Optional> $optionals
* @param Sequence<Aggregate\Collection> $collections
*/
private function __construct(
string $class,
Aggregate\Identity $id,
Set $properties,
Set $entities,
Set $optionals,
Set $collections,
Sequence $properties,
Sequence $entities,
Sequence $optionals,
Sequence $collections,
) {
$this->class = $class;
$this->id = $id;
Expand Down Expand Up @@ -116,33 +116,33 @@ public function id(): Aggregate\Identity
}

/**
* @return Set<Aggregate\Property<T, mixed>>
* @return Sequence<Aggregate\Property<T, mixed>>
*/
public function properties(): Set
public function properties(): Sequence
{
return $this->properties;
}

/**
* @return Set<Aggregate\Entity>
* @return Sequence<Aggregate\Entity>
*/
public function entities(): Set
public function entities(): Sequence
{
return $this->entities;
}

/**
* @return Set<Aggregate\Optional>
* @return Sequence<Aggregate\Optional>
*/
public function optionals(): Set
public function optionals(): Sequence
{
return $this->optionals;
}

/**
* @return Set<Aggregate\Collection>
* @return Sequence<Aggregate\Collection>
*/
public function collections(): Set
public function collections(): Sequence
{
return $this->collections;
}
Expand Down
Loading

0 comments on commit c98dbcd

Please sign in to comment.