Skip to content

Commit fc5a2a9

Browse files
authored
Merge pull request #101 from Innmind/deprecations
Deprecate `Set::lazy()` and `Sequence::defer()`
2 parents e54a275 + e3a7902 commit fc5a2a9

10 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
- Lazy `Sequence` internal operations are now in dedicated classes to allow PHP to cache the code and improve stack traces
1212

13+
### Deprecated
14+
15+
- `Set::lazy()`
16+
- `Sequence::defer()`
17+
1318
## 6.6.0 - 2026-11-22
1419

1520
### Changed

‎docs/structures/sequence.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ $sequence = Sequence::defer((function() {
3232

3333
The method ask a generator that will provide the elements. Once the elements are loaded they are kept in memory so you can run multiple operations on it without loading the file twice.
3434

35+
!!! warning ""
36+
This method is deprecated and will be removed in the next major release.
37+
3538
!!! warning ""
3639
Beware of the case where the source you read the elements is not altered before the first use of the sequence.
3740

‎docs/structures/set.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ $set = Set::lazy(function() {
2323
});
2424
```
2525

26+
!!! warning ""
27+
This method is deprecated and will be removed in the next major release.
28+
2629
!!! warning ""
2730
Since the elements are reloaded each time the immutability responsability is up to you because the source may change or if you generate objects it will generate new objects each time (so if you make strict comparison it will fail).
2831

‎src/Identity/Defer.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public function toSequence(): Sequence
6565
{
6666
$captured = $this->capture();
6767

68-
/** @psalm-suppress ImpureFunctionCall */
68+
/**
69+
* @psalm-suppress ImpureFunctionCall
70+
* @psalm-suppress DeprecatedMethod
71+
*/
6972
return Sequence::defer((static fn() => yield self::detonate($captured))());
7073
}
7174

‎src/Maybe/Defer.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ public function toSequence(): Sequence
106106
{
107107
$captured = $this->capture();
108108

109-
/** @psalm-suppress ImpureFunctionCall */
109+
/**
110+
* @psalm-suppress ImpureFunctionCall
111+
* @psalm-suppress DeprecatedMethod
112+
*/
110113
return Sequence::defer((static function() use ($captured) {
111114
/** @var V $value */
112115
foreach (self::detonate($captured)->toSequence()->toList() as $value) {

‎src/Sequence.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static function of(...$values): self
6464
*
6565
* @template V
6666
* @psalm-pure
67+
* @deprecated
6768
*
6869
* @param \Generator<V> $generator
6970
*

‎src/Sequence/Defer.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ public function via(callable $map): Sequence
524524
{
525525
$self = $this;
526526

527-
/** @psalm-suppress ImpureFunctionCall */
527+
/**
528+
* @psalm-suppress ImpureFunctionCall
529+
* @psalm-suppress DeprecatedMethod
530+
*/
528531
return Sequence::defer((static function() use ($self, $map) {
529532
yield $map($self);
530533
})())->flatMap(static fn($sequence) => $sequence);
@@ -953,6 +956,7 @@ public function toSet(): Set
953956

954957
/**
955958
* @psalm-suppress ImpureFunctionCall
959+
* @psalm-suppress DeprecatedMethod
956960
*/
957961
return Set::lazy(
958962
static function() use (&$captured): \Generator {

‎src/Sequence/Lazy.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ public function toIdentity(): Identity
556556
#[\Override]
557557
public function toSet(): Set
558558
{
559+
/** @psalm-suppress DeprecatedMethod */
559560
return Set::lazy($this->values);
560561
}
561562

‎src/Sequence/Snap.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ public function toSet(): Set
432432
// Set starts to load a value it memoize $this (thus loading everything
433433
// in memory). And all new iterations over the Set will reuse the
434434
// already loaded data.
435+
/** @psalm-suppress DeprecatedMethod */
435436
return Set::lazy(static function() use ($self) {
436437
yield from $self->iterator();
437438
})->snap();

‎src/Set.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static function of(...$values): self
6060
*
6161
* @template V
6262
* @psalm-pure
63+
* @deprecated
6364
*
6465
* @param callable(RegisterCleanup): \Generator<V> $generator
6566
*

0 commit comments

Comments
 (0)