Skip to content
Merged
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
26 changes: 24 additions & 2 deletions src/Collection/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ArrayAccess;
use Closure;
use Generator;
use LogicException;
use Override;
use WizDevelop\PhpMonad\Option;
use WizDevelop\PhpMonad\Result;
Expand Down Expand Up @@ -109,7 +110,7 @@ final public static function tryFrom(iterable $elements): Result
*
* @template TTryFromValue of TValue
*
* @param iterable<int,(Result<TTryFromValue,IErrorValue>|Result)> $results
* @param iterable<int,(Result<TTryFromValue,IErrorValue>|Result<TTryFromValue,IErrorValue[]>|Result)> $results
* @return Result<static<TTryFromValue>,ValueObjectError>
*/
/**
Expand All @@ -122,9 +123,30 @@ final public static function tryFromResults(iterable $results): Result

$elementsResult = Result\combineWithErrorValue(...$elements);
if ($elementsResult->isErr()) {
$flattenErrs = [];
foreach ($elementsResult->unwrapErr() as $err) {
if ($err instanceof IErrorValue) { // @phpstan-ignore-line
$flattenErrs[] = $err;
} elseif (is_array($err)) {
foreach ($err as $e) {
if ($e instanceof IErrorValue) { // @phpstan-ignore-line
$flattenErrs[] = $e;
} else {
throw new LogicException(
'Invalid error value type in array. Expected IErrorValue.',
);
}
}
} else {
throw new LogicException(
'Invalid error value type. Expected IErrorValue or array of IErrorValue.',
);
}
}

return Result\err(ValueObjectError::collection()->invalidElementValues(
static::class,
...$elementsResult->unwrapErr()
...$flattenErrs,
));
}

Expand Down
Loading