Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  call all registered cleanup callbacks instead of the last declared one
  directly open the readme
  • Loading branch information
Baptouuuu committed Oct 11, 2023
2 parents e7968ea + 5548238 commit dad4c41
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 98 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.1.0 - 2023-10-11

### Changed

- Registered cleanup callbacks for lazy `Sequence`s and `Set`s are all called now for composed structures, instead of the last one

## 5.0.0 - 2023-09-16

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

A set of classes to wrap PHP primitives to build immutable data.

[Documentation](docs/)
[Documentation](docs/README.md)

## Installation

Expand Down
66 changes: 66 additions & 0 deletions src/RegisterCleanup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types = 1);

namespace Innmind\Immutable;

final class RegisterCleanup
{
/** @var callable(): void */
private $cleanup;
private ?self $child = null;

/**
* @psalm-mutation-free
*
* @param callable(): void $cleanup
*/
private function __construct(callable $cleanup)
{
$this->cleanup = $cleanup;
}

/**
* @param callable(): void $cleanup
*/
public function __invoke(callable $cleanup): void
{
$this->cleanup = $cleanup;
}

/**
* @internal
* @psalm-pure
*/
public static function noop(): self
{
return new self(static fn() => null);
}

/**
* @internal
*/
public function push(): self
{
return $this->child = self::noop();
}

/**
* @internal
*/
public function pop(): void
{
$this->child = null;
}

/**
* @internal
*/
public function cleanup(): void
{
if ($this->child) {
$this->child->cleanup();
}

($this->cleanup)();
}
}
1 change: 0 additions & 1 deletion src/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static function defer(\Generator $generator): self
*
* @template V
* @psalm-pure
* @psalm-type RegisterCleanup = callable(callable(): void): void
*
* @param callable(RegisterCleanup): \Generator<V> $generator
*
Expand Down
Loading

0 comments on commit dad4c41

Please sign in to comment.