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
2 changes: 2 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use JsonSerializable;
use Noctud\Collection\Exception\ConversionException;
use Noctud\Collection\Exception\NoSuchElementException;
use Noctud\Collection\Exception\NonReplayableSourceException;
use Noctud\Collection\Exception\UnsupportedOperationException;
use Noctud\Collection\List\ImmutableList;
use Noctud\Collection\List\ListInterface;
Expand Down Expand Up @@ -546,6 +547,7 @@ public function windowed(int $size, int $step = 1, bool $partialWindows = false)
* @template U
* @param iterable<U> $other
* @return ListInterface<array{E, U}>
* @throws NonReplayableSourceException If the other iterator cannot be rewound
*/
#[NoDiscard]
public function zip(iterable $other): ListInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ConversionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

use LogicException;

final class ConversionException extends LogicException
final class ConversionException extends LogicException implements NoctudCollectionException
{
}
2 changes: 1 addition & 1 deletion src/Exception/IndexOutOfBoundsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

use LogicException;

final class IndexOutOfBoundsException extends LogicException
final class IndexOutOfBoundsException extends LogicException implements NoctudCollectionException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidKeyTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

use LogicException;

final class InvalidKeyTypeException extends LogicException
final class InvalidKeyTypeException extends LogicException implements NoctudCollectionException
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidSequenceSourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Thrown when a sequence source closure returns a non-iterable value.
*/
final class InvalidSequenceSourceException extends LogicException
final class InvalidSequenceSourceException extends LogicException implements SourceException
{
public static function closureReturnedNonIterable(mixed $produced): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/NoSuchElementException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Noctud\Collection\Collection;
use Noctud\Collection\Sequence\Sequence;

final class NoSuchElementException extends LogicException
final class NoSuchElementException extends LogicException implements NoctudCollectionException
{
use NamesItsSubject;

Expand Down
23 changes: 23 additions & 0 deletions src/Exception/NoctudCollectionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* This file is part of the Noctud Collection.
* Copyright (c) Noctud.dev
*/

declare(strict_types=1);

namespace Noctud\Collection\Exception;

use Throwable;

/**
* Marks every exception this library raises, so a single catch covers them all.
*
* An interface rather than a base class: each failure keeps the parent that describes it best
* - LogicException for all of them today - and a third-party collection built on this library
* can join the family without giving up the exception hierarchy it already has.
*/
interface NoctudCollectionException extends Throwable
{
}
2 changes: 1 addition & 1 deletion src/Exception/NonReplayableSourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Thrown when an iterable that can only be walked once is walked again.
*/
final class NonReplayableSourceException extends UnsupportedOperationException
final class NonReplayableSourceException extends UnsupportedOperationException implements SourceException
{
public static function sequenceSourceAlreadyIterated(): self
{
Expand Down
22 changes: 22 additions & 0 deletions src/Exception/SourceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* This file is part of the Noctud Collection.
* Copyright (c) Noctud.dev
*/

declare(strict_types=1);

namespace Noctud\Collection\Exception;

/**
* Marks the failures raised when walking a source rather than by what a method does: a
* source that refuses to hand back a fresh pass, or one that hands back something not
* iterable.
*
* Methods that walk a source declare this single type rather than the concrete exceptions
* behind it - which one surfaces depends on the source, not on the method called.
*/
interface SourceException extends NoctudCollectionException
{
}
2 changes: 1 addition & 1 deletion src/Exception/UnsupportedOperationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Thrown when a mutating method is called on an immutable collection/map or when a
* requested operation is not valid in the current state (e.g., removing from an empty list).
*/
class UnsupportedOperationException extends LogicException
class UnsupportedOperationException extends LogicException implements NoctudCollectionException
{
use NamesItsSubject;

Expand Down
Loading
Loading