Skip to content

Commit 320bdb2

Browse files
committed
Merge branch 'develop'
* develop: specify next release discard psalm errors add Set::unsorted() CS
2 parents 08558e5 + 32ceacb commit 320bdb2

30 files changed

+78
-56
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 5.4.0 - 2024-05-29
4+
5+
### Added
6+
7+
- `Innmind\Immutable\Set::unsorted()`
8+
39
## 5.3.0 - 2023-11-06
410

511
### Added

docs/SET.md

+10
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ $sequence = Set::ints(1, 4, 2, 3)->sort(fn($a, $b) => $a <=> $b);
267267
$sequence->equals(Sequence::ints(1, 2, 3, 4));
268268
```
269269

270+
## `->unsorted()`
271+
272+
It will transform the set into an unordered sequence.
273+
274+
```php
275+
$sequence = Set::ints(1, 4, 2, 3)->unsorted();
276+
// is the same as
277+
$sequence = Sequence::of(...Set::of(1, 4, 2, 3)->toList());
278+
```
279+
270280
## `->merge()`
271281

272282
Create a new set with all the elements from both sets.

proofs/predicate.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
yield test(
88
'Or predicate',
99
static function($assert) {
10-
$array = new \SplFixedArray;
10+
$array = new SplFixedArray;
1111

1212
$assert->true(
13-
Instance::of(\Countable::class)
14-
->or(Instance::of(\stdClass::class))
13+
Instance::of(Countable::class)
14+
->or(Instance::of(stdClass::class))
1515
($array),
1616
);
1717
$assert->true(
18-
Instance::of(\stdClass::class)
19-
->or(Instance::of(\Countable::class))
18+
Instance::of(stdClass::class)
19+
->or(Instance::of(Countable::class))
2020
($array),
2121
);
2222
$assert->false(
23-
Instance::of(\Throwable::class)
24-
->or(Instance::of(\Unknown::class))
23+
Instance::of(Throwable::class)
24+
->or(Instance::of(Unknown::class))
2525
($array),
2626
);
2727
},
@@ -30,21 +30,21 @@ static function($assert) {
3030
yield test(
3131
'And predicate',
3232
static function($assert) {
33-
$array = new \SplFixedArray;
33+
$array = new SplFixedArray;
3434

3535
$assert->true(
36-
Instance::of(\Countable::class)
37-
->and(Instance::of(\Traversable::class))
36+
Instance::of(Countable::class)
37+
->and(Instance::of(Traversable::class))
3838
($array),
3939
);
4040
$assert->false(
41-
Instance::of(\Throwable::class)
42-
->and(Instance::of(\Countable::class))
41+
Instance::of(Throwable::class)
42+
->and(Instance::of(Countable::class))
4343
($array),
4444
);
4545
$assert->false(
46-
Instance::of(\Countable::class)
47-
->and(Instance::of(\Throwable::class))
46+
Instance::of(Countable::class)
47+
->and(Instance::of(Throwable::class))
4848
($array),
4949
);
5050
},

proofs/set.php

+18
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,22 @@ static function($assert, $first, $rest) {
3434
$assert->same($rest, $packed[1]->toList());
3535
},
3636
);
37+
38+
yield proof(
39+
'Set::unsorted()',
40+
given(
41+
DataSet\Sequence::of(DataSet\Type::any()),
42+
),
43+
static function($assert, $values) {
44+
$set = Set::of(...$values);
45+
$sequence = $set->unsorted();
46+
47+
$assert->true(
48+
$sequence->matches($set->contains(...)),
49+
);
50+
$assert->true(
51+
$set->matches($sequence->contains(...)),
52+
);
53+
},
54+
);
3755
};

src/Accumulate.php

+4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function key(): mixed
5454

5555
public function next(): void
5656
{
57+
/** @psalm-suppress InaccessibleProperty */
5758
\next($this->keys);
59+
/** @psalm-suppress InaccessibleProperty */
5860
\next($this->values);
5961

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

6668
public function rewind(): void
6769
{
70+
/** @psalm-suppress InaccessibleProperty */
6871
\reset($this->keys);
72+
/** @psalm-suppress InaccessibleProperty */
6973
\reset($this->values);
7074
}
7175

src/Map/DoubleIndex.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use Innmind\Immutable\{
77
Map,
8-
Str,
98
Sequence,
109
Set,
1110
Pair,

src/Map/Implementation.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use Innmind\Immutable\{
77
Map,
8-
Str,
98
Set,
109
Sequence,
1110
Pair,

src/Map/ObjectKeys.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use Innmind\Immutable\{
77
Map,
8-
Str,
98
Sequence,
109
Set,
1110
Pair,

src/Map/Primitive.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use Innmind\Immutable\{
77
Map,
8-
Str,
98
Sequence,
109
Set,
1110
Pair,
@@ -328,7 +327,10 @@ public function reduce($carry, callable $reducer)
328327

329328
public function empty(): bool
330329
{
331-
/** @psalm-suppress MixedArgumentTypeCoercion */
330+
/**
331+
* @psalm-suppress InaccessibleProperty
332+
* @psalm-suppress MixedArgumentTypeCoercion
333+
*/
332334
\reset($this->values);
333335

334336
/** @psalm-suppress MixedArgumentTypeCoercion */

src/Sequence/Defer.php

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Innmind\Immutable\{
77
Map,
88
Sequence,
9-
Str,
109
Set,
1110
Maybe,
1211
Accumulate,

src/Sequence/Implementation.php

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Innmind\Immutable\{
77
Map,
88
Sequence,
9-
Str,
109
Set,
1110
Maybe,
1211
SideEffect,

src/Sequence/Lazy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Innmind\Immutable\{
77
Map,
88
Sequence,
9-
Str,
109
Set,
1110
Maybe,
1211
SideEffect,
@@ -273,6 +272,7 @@ public function contains($element): bool
273272
/** @psalm-suppress ImpureFunctionCall */
274273
$generator = ($this->values)($register);
275274

275+
/** @psalm-suppress ImpureMethodCall */
276276
foreach ($generator as $value) {
277277
if ($value === $element) {
278278
/** @psalm-suppress ImpureMethodCall */

src/Sequence/Primitive.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Innmind\Immutable\{
77
Map,
88
Sequence,
9-
Str,
109
Set,
1110
Maybe,
1211
SideEffect,
@@ -385,7 +384,10 @@ public function intersect(Implementation $sequence): self
385384
public function sort(callable $function): self
386385
{
387386
$self = clone $this;
388-
/** @psalm-suppress ImpureFunctionCall */
387+
/**
388+
* @psalm-suppress InaccessibleProperty
389+
* @psalm-suppress ImpureFunctionCall
390+
*/
389391
\usort($self->values, $function);
390392

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

533+
/** @psalm-suppress ImpureMethodCall */
531534
foreach ($values as $value) {
532535
$aggregated[] = $value;
533536
}

src/Set.php

+13
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,19 @@ public function sort(callable $function): Sequence
362362
return $this->implementation->sort($function);
363363
}
364364

365+
/**
366+
* Return an unsorted sequence
367+
*
368+
* @return Sequence<T>
369+
*/
370+
public function unsorted(): Sequence
371+
{
372+
return $this
373+
->implementation
374+
->sequence()
375+
->toSequence();
376+
}
377+
365378
/**
366379
* Create a new set with elements of both sets
367380
*

src/Set/Defer.php

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Map,
88
Sequence,
99
Set,
10-
Str,
1110
Maybe,
1211
SideEffect,
1312
};

src/Set/Implementation.php

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Map,
88
Sequence,
99
Set,
10-
Str,
1110
Maybe,
1211
SideEffect,
1312
};

src/Set/Lazy.php

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Map,
88
Sequence,
99
Set,
10-
Str,
1110
Maybe,
1211
SideEffect,
1312
RegisterCleanup,

src/Set/Primitive.php

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Map,
88
Sequence,
99
Set,
10-
Str,
1110
Maybe,
1211
SideEffect,
1312
};

tests/Map/DoubleIndexTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
Map\DoubleIndex,
88
Map\Implementation,
99
Map,
10-
Pair,
11-
Str,
1210
Set,
1311
Sequence,
1412
};
@@ -20,7 +18,7 @@ public function testInterface()
2018
{
2119
$m = new DoubleIndex;
2220

23-
$this->assertInstanceOf(Map\Implementation::class, $m);
21+
$this->assertInstanceOf(Implementation::class, $m);
2422
$this->assertInstanceOf(\Countable::class, $m);
2523
}
2624

tests/Map/ObjectKeysTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
Map\DoubleIndex,
99
Map\Implementation,
1010
Map,
11-
Pair,
12-
Str,
1311
Set,
1412
Sequence,
1513
};
@@ -21,7 +19,7 @@ public function testInterface()
2119
{
2220
$m = new ObjectKeys;
2321

24-
$this->assertInstanceOf(Map\Implementation::class, $m);
22+
$this->assertInstanceOf(Implementation::class, $m);
2523
$this->assertInstanceOf(\Countable::class, $m);
2624
}
2725

tests/Map/PrimitiveTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
Map\Primitive,
88
Map\Implementation,
99
Map,
10-
Pair,
11-
Str,
1210
Set,
1311
Sequence,
1412
};
@@ -20,7 +18,7 @@ public function testInterface()
2018
{
2119
$m = new Primitive;
2220

23-
$this->assertInstanceOf(Map\Implementation::class, $m);
21+
$this->assertInstanceOf(Implementation::class, $m);
2422
$this->assertInstanceOf(\Countable::class, $m);
2523
}
2624

tests/MapTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
use Innmind\Immutable\{
77
Map,
8-
Pair,
9-
Str,
108
Set,
119
Sequence,
1210
};

tests/Sequence/DeferTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
Sequence\Defer,
88
Sequence\Implementation,
99
Map,
10-
Sequence,
11-
Str,
12-
Set,
1310
SideEffect,
1411
};
1512
use Innmind\BlackBox\PHPUnit\Framework\TestCase;

tests/Sequence/LazyTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
Sequence\Lazy,
88
Sequence\Implementation,
99
Map,
10-
Sequence,
11-
Str,
12-
Set,
1310
SideEffect,
1411
};
1512
use Innmind\BlackBox\PHPUnit\Framework\TestCase;

tests/Sequence/PrimitiveTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
Sequence\Primitive,
88
Sequence\Implementation,
99
Map,
10-
Sequence,
11-
Str,
12-
Set,
1310
SideEffect,
1411
};
1512
use Innmind\BlackBox\PHPUnit\Framework\TestCase;

tests/Set/DeferTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
use Innmind\Immutable\{
77
Set\Defer,
88
Set\Implementation,
9-
Set,
109
Map,
11-
Str,
1210
Sequence,
1311
SideEffect,
1412
};

tests/Set/LazyTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
use Innmind\Immutable\{
77
Set\Lazy,
88
Set\Implementation,
9-
Set,
109
Map,
11-
Str,
1210
Sequence,
1311
SideEffect,
1412
};

0 commit comments

Comments
 (0)