Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- `Innmind\Immutable\Set` no longer implements `Countable`
- Requires PHP `8.4`
- `Innmind\Immutable\Predicate` is now a final class
- `Innmind\Immutable\Monoid\*` are now enums with a single case called `monoid`

### Removed

Expand Down
2 changes: 1 addition & 1 deletion docs/structures/sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ use Innmind\Immutable\Monoid\Concat;

$lines = Sequence::of("foo\n", "bar\n", 'baz')
->map(fn($line) => Str::of($line))
->fold(new Concat);
->fold(Concat::monoid);

$lines->equals("foo\nbar\nbaz"); // true
```
Expand Down
4 changes: 2 additions & 2 deletions proofs/monoid/arrayMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
yield properties(
'ArrayMerge properties',
Monoid::properties($set, $equals),
Set::of(new ArrayMerge),
Set::of(ArrayMerge::monoid),
);

foreach (Monoid::list($set, $equals) as $property) {
yield proof(
'ArrayMerge property',
given($property),
static fn($assert, $property) => $property->ensureHeldBy($assert, new ArrayMerge),
static fn($assert, $property) => $property->ensureHeldBy($assert, ArrayMerge::monoid),
);
}
};
4 changes: 2 additions & 2 deletions proofs/monoid/concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
yield properties(
'Concat properties',
Monoid::properties($set, $equals),
Set::of(new Concat),
Set::of(Concat::monoid),
);

foreach (Monoid::list($set, $equals) as $property) {
yield proof(
'Concat property',
given($property),
static fn($assert, $property) => $property->ensureHeldBy($assert, new Concat),
static fn($assert, $property) => $property->ensureHeldBy($assert, Concat::monoid),
);
}
};
2 changes: 1 addition & 1 deletion proofs/sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static function($assert, $string, $chunk) {
$string,
$chunks
->flatMap(static fn($chars) => $chars)
->fold(new Concat)
->fold(Concat::monoid)
->toString(),
);
},
Expand Down
6 changes: 4 additions & 2 deletions src/Monoid/Append.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
* @psalm-immutable
* @implements Monoid<Sequence<T>>
*/
final class Append implements Monoid
enum Append implements Monoid
{
case monoid;

/**
* @template C of object
*
Expand All @@ -26,7 +28,7 @@ final class Append implements Monoid
public static function of(?string $class = null): self
{
/** @var self<C> */
return new self;
return self::monoid;
}

#[\Override]
Expand Down
4 changes: 3 additions & 1 deletion src/Monoid/ArrayMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
* @psalm-immutable
* @implements Monoid<array<T, U>>
*/
final class ArrayMerge implements Monoid
enum ArrayMerge implements Monoid
{
case monoid;

#[\Override]
public function identity(): mixed
{
Expand Down
4 changes: 3 additions & 1 deletion src/Monoid/Concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
* @psalm-immutable
* @implements Monoid<Str>
*/
final class Concat implements Monoid
enum Concat implements Monoid
{
case monoid;

#[\Override]
public function identity(): Str
{
Expand Down
6 changes: 4 additions & 2 deletions src/Monoid/MergeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
* @psalm-immutable
* @implements Monoid<Map<T, U>>
*/
final class MergeMap implements Monoid
enum MergeMap implements Monoid
{
case monoid;

/**
* @template A of object
* @template B of object
Expand All @@ -29,7 +31,7 @@ final class MergeMap implements Monoid
public static function of(?string $key = null, ?string $value = null): self
{
/** @var self<A, B> */
return new self;
return self::monoid;
}

#[\Override]
Expand Down
6 changes: 4 additions & 2 deletions src/Monoid/MergeSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
* @psalm-immutable
* @implements Monoid<Set<T>>
*/
final class MergeSet implements Monoid
enum MergeSet implements Monoid
{
case monoid;

/**
* @template C of object
*
Expand All @@ -26,7 +28,7 @@ final class MergeSet implements Monoid
public static function of(?string $class = null): self
{
/** @var self<C> */
return new self;
return self::monoid;
}

#[\Override]
Expand Down
4 changes: 2 additions & 2 deletions tests/Monoid/ConcatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class ConcatTest extends TestCase
{
public function testInterface()
{
$this->assertInstanceOf(Monoid::class, new Concat);
$this->assertInstanceOf(Monoid::class, Concat::monoid);
}

public function testCombine()
{
$str = (new Concat)->combine(Str::of('foo'), Str::of('bar'));
$str = Concat::monoid->combine(Str::of('foo'), Str::of('bar'));

$this->assertInstanceOf(Str::class, $str);
$this->assertSame(
Expand Down
4 changes: 2 additions & 2 deletions tests/SequenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,12 @@ public function testLazyMatch()

public function testFold()
{
$str = Sequence::of(Str::of('foo'), Str::of('bar'), Str::of('baz'))->fold(new Concat);
$str = Sequence::of(Str::of('foo'), Str::of('bar'), Str::of('baz'))->fold(Concat::monoid);

$this->assertInstanceOf(Str::class, $str);
$this->assertSame('foobarbaz', $str->toString());

$str = Sequence::of(Str::of('baz'), Str::of('foo'), Str::of('bar'))->fold(new Concat);
$str = Sequence::of(Str::of('baz'), Str::of('foo'), Str::of('bar'))->fold(Concat::monoid);

$this->assertInstanceOf(Str::class, $str);
$this->assertSame('bazfoobar', $str->toString());
Expand Down