Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  discard psalm errors
  add Set::unsorted()
  CS
  • Loading branch information
Baptouuuu committed May 29, 2024
2 parents 08558e5 + 32ceacb commit 320bdb2
Show file tree
Hide file tree
Showing 30 changed files with 78 additions and 56 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 5.4.0 - 2024-05-29

### Added

- `Innmind\Immutable\Set::unsorted()`

## 5.3.0 - 2023-11-06

### Added
Expand Down
10 changes: 10 additions & 0 deletions docs/SET.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ $sequence = Set::ints(1, 4, 2, 3)->sort(fn($a, $b) => $a <=> $b);
$sequence->equals(Sequence::ints(1, 2, 3, 4));
```

## `->unsorted()`

It will transform the set into an unordered sequence.

```php
$sequence = Set::ints(1, 4, 2, 3)->unsorted();
// is the same as
$sequence = Sequence::of(...Set::of(1, 4, 2, 3)->toList());
```

## `->merge()`

Create a new set with all the elements from both sets.
Expand Down
28 changes: 14 additions & 14 deletions proofs/predicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
yield test(
'Or predicate',
static function($assert) {
$array = new \SplFixedArray;
$array = new SplFixedArray;

$assert->true(
Instance::of(\Countable::class)
->or(Instance::of(\stdClass::class))
Instance::of(Countable::class)
->or(Instance::of(stdClass::class))
($array),
);
$assert->true(
Instance::of(\stdClass::class)
->or(Instance::of(\Countable::class))
Instance::of(stdClass::class)
->or(Instance::of(Countable::class))
($array),
);
$assert->false(
Instance::of(\Throwable::class)
->or(Instance::of(\Unknown::class))
Instance::of(Throwable::class)
->or(Instance::of(Unknown::class))
($array),
);
},
Expand All @@ -30,21 +30,21 @@ static function($assert) {
yield test(
'And predicate',
static function($assert) {
$array = new \SplFixedArray;
$array = new SplFixedArray;

$assert->true(
Instance::of(\Countable::class)
->and(Instance::of(\Traversable::class))
Instance::of(Countable::class)
->and(Instance::of(Traversable::class))
($array),
);
$assert->false(
Instance::of(\Throwable::class)
->and(Instance::of(\Countable::class))
Instance::of(Throwable::class)
->and(Instance::of(Countable::class))
($array),
);
$assert->false(
Instance::of(\Countable::class)
->and(Instance::of(\Throwable::class))
Instance::of(Countable::class)
->and(Instance::of(Throwable::class))
($array),
);
},
Expand Down
18 changes: 18 additions & 0 deletions proofs/set.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ static function($assert, $first, $rest) {
$assert->same($rest, $packed[1]->toList());
},
);

yield proof(
'Set::unsorted()',
given(
DataSet\Sequence::of(DataSet\Type::any()),
),
static function($assert, $values) {
$set = Set::of(...$values);
$sequence = $set->unsorted();

$assert->true(
$sequence->matches($set->contains(...)),
);
$assert->true(
$set->matches($sequence->contains(...)),
);
},
);
};
4 changes: 4 additions & 0 deletions src/Accumulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function key(): mixed

public function next(): void
{
/** @psalm-suppress InaccessibleProperty */
\next($this->keys);
/** @psalm-suppress InaccessibleProperty */
\next($this->values);

if ($this->reachedCacheEnd()) {
Expand All @@ -65,7 +67,9 @@ public function next(): void

public function rewind(): void
{
/** @psalm-suppress InaccessibleProperty */
\reset($this->keys);
/** @psalm-suppress InaccessibleProperty */
\reset($this->values);
}

Expand Down
1 change: 0 additions & 1 deletion src/Map/DoubleIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Innmind\Immutable\{
Map,
Str,
Sequence,
Set,
Pair,
Expand Down
1 change: 0 additions & 1 deletion src/Map/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Innmind\Immutable\{
Map,
Str,
Set,
Sequence,
Pair,
Expand Down
1 change: 0 additions & 1 deletion src/Map/ObjectKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Innmind\Immutable\{
Map,
Str,
Sequence,
Set,
Pair,
Expand Down
6 changes: 4 additions & 2 deletions src/Map/Primitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Innmind\Immutable\{
Map,
Str,
Sequence,
Set,
Pair,
Expand Down Expand Up @@ -328,7 +327,10 @@ public function reduce($carry, callable $reducer)

public function empty(): bool
{
/** @psalm-suppress MixedArgumentTypeCoercion */
/**
* @psalm-suppress InaccessibleProperty
* @psalm-suppress MixedArgumentTypeCoercion
*/
\reset($this->values);

/** @psalm-suppress MixedArgumentTypeCoercion */
Expand Down
1 change: 0 additions & 1 deletion src/Sequence/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Innmind\Immutable\{
Map,
Sequence,
Str,
Set,
Maybe,
Accumulate,
Expand Down
1 change: 0 additions & 1 deletion src/Sequence/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Innmind\Immutable\{
Map,
Sequence,
Str,
Set,
Maybe,
SideEffect,
Expand Down
2 changes: 1 addition & 1 deletion src/Sequence/Lazy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Innmind\Immutable\{
Map,
Sequence,
Str,
Set,
Maybe,
SideEffect,
Expand Down Expand Up @@ -273,6 +272,7 @@ public function contains($element): bool
/** @psalm-suppress ImpureFunctionCall */
$generator = ($this->values)($register);

/** @psalm-suppress ImpureMethodCall */
foreach ($generator as $value) {
if ($value === $element) {
/** @psalm-suppress ImpureMethodCall */
Expand Down
7 changes: 5 additions & 2 deletions src/Sequence/Primitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Innmind\Immutable\{
Map,
Sequence,
Str,
Set,
Maybe,
SideEffect,
Expand Down Expand Up @@ -385,7 +384,10 @@ public function intersect(Implementation $sequence): self
public function sort(callable $function): self
{
$self = clone $this;
/** @psalm-suppress ImpureFunctionCall */
/**
* @psalm-suppress InaccessibleProperty
* @psalm-suppress ImpureFunctionCall
*/
\usort($self->values, $function);

return $self;
Expand Down Expand Up @@ -528,6 +530,7 @@ public function aggregate(callable $map, callable $exfiltrate): self
$values = $aggregate(static fn($a, $b) => $exfiltrate($map($a, $b))->iterator());
$aggregated = [];

/** @psalm-suppress ImpureMethodCall */
foreach ($values as $value) {
$aggregated[] = $value;
}
Expand Down
13 changes: 13 additions & 0 deletions src/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ public function sort(callable $function): Sequence
return $this->implementation->sort($function);
}

/**
* Return an unsorted sequence
*
* @return Sequence<T>
*/
public function unsorted(): Sequence
{
return $this
->implementation
->sequence()
->toSequence();
}

/**
* Create a new set with elements of both sets
*
Expand Down
1 change: 0 additions & 1 deletion src/Set/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Map,
Sequence,
Set,
Str,
Maybe,
SideEffect,
};
Expand Down
1 change: 0 additions & 1 deletion src/Set/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Map,
Sequence,
Set,
Str,
Maybe,
SideEffect,
};
Expand Down
1 change: 0 additions & 1 deletion src/Set/Lazy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Map,
Sequence,
Set,
Str,
Maybe,
SideEffect,
RegisterCleanup,
Expand Down
1 change: 0 additions & 1 deletion src/Set/Primitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Map,
Sequence,
Set,
Str,
Maybe,
SideEffect,
};
Expand Down
4 changes: 1 addition & 3 deletions tests/Map/DoubleIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Map\DoubleIndex,
Map\Implementation,
Map,
Pair,
Str,
Set,
Sequence,
};
Expand All @@ -20,7 +18,7 @@ public function testInterface()
{
$m = new DoubleIndex;

$this->assertInstanceOf(Map\Implementation::class, $m);
$this->assertInstanceOf(Implementation::class, $m);
$this->assertInstanceOf(\Countable::class, $m);
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Map/ObjectKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Map\DoubleIndex,
Map\Implementation,
Map,
Pair,
Str,
Set,
Sequence,
};
Expand All @@ -21,7 +19,7 @@ public function testInterface()
{
$m = new ObjectKeys;

$this->assertInstanceOf(Map\Implementation::class, $m);
$this->assertInstanceOf(Implementation::class, $m);
$this->assertInstanceOf(\Countable::class, $m);
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Map/PrimitiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Map\Primitive,
Map\Implementation,
Map,
Pair,
Str,
Set,
Sequence,
};
Expand All @@ -20,7 +18,7 @@ public function testInterface()
{
$m = new Primitive;

$this->assertInstanceOf(Map\Implementation::class, $m);
$this->assertInstanceOf(Implementation::class, $m);
$this->assertInstanceOf(\Countable::class, $m);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

use Innmind\Immutable\{
Map,
Pair,
Str,
Set,
Sequence,
};
Expand Down
3 changes: 0 additions & 3 deletions tests/Sequence/DeferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
Sequence\Defer,
Sequence\Implementation,
Map,
Sequence,
Str,
Set,
SideEffect,
};
use Innmind\BlackBox\PHPUnit\Framework\TestCase;
Expand Down
3 changes: 0 additions & 3 deletions tests/Sequence/LazyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
Sequence\Lazy,
Sequence\Implementation,
Map,
Sequence,
Str,
Set,
SideEffect,
};
use Innmind\BlackBox\PHPUnit\Framework\TestCase;
Expand Down
3 changes: 0 additions & 3 deletions tests/Sequence/PrimitiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
Sequence\Primitive,
Sequence\Implementation,
Map,
Sequence,
Str,
Set,
SideEffect,
};
use Innmind\BlackBox\PHPUnit\Framework\TestCase;
Expand Down
2 changes: 0 additions & 2 deletions tests/Set/DeferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use Innmind\Immutable\{
Set\Defer,
Set\Implementation,
Set,
Map,
Str,
Sequence,
SideEffect,
};
Expand Down
2 changes: 0 additions & 2 deletions tests/Set/LazyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use Innmind\Immutable\{
Set\Lazy,
Set\Implementation,
Set,
Map,
Str,
Sequence,
SideEffect,
};
Expand Down
Loading

0 comments on commit 320bdb2

Please sign in to comment.