Skip to content

Commit

Permalink
correct foldr for Traversable
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Sep 27, 2023
1 parent 3c4d2a5 commit 8fc58a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic versioning](http://semver.org/).
- do not flip arguments on `ListL/ConcatenationMonoid`
- introduce `Alt` and `Plus` typeclasses
- define `ConstantSemigroup`
- fix `foldr` behavior for lists
- correct `foldr` implementation for `ListL` and `Traversable`

## [2.0.0] - 2023-03-21

Expand All @@ -22,6 +22,7 @@ and this project adheres to [Semantic versioning](http://semver.org/).

- introduce `OppositeSemigroup` and `OppositMonoid`
- do not flip arguments on `ListL/ConcatenationMonoid`
- correct `foldr` implementation for `ListL` and `Traversable`

## [1.3.0] - 2023-08-23

Expand Down
7 changes: 7 additions & 0 deletions src/Instances/Traversable/TraversableFoldable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ public function foldr(callable $f, mixed $b, HK1 $a): mixed

$ret = $b;

$reverseArrayA = [];

/** @psalm-suppress ImpureMethodCall */
foreach ($arrayA as $element) {
$reverseArrayA = array_merge([$element], $reverseArrayA);
}

/** @psalm-suppress ImpureMethodCall */
foreach ($reverseArrayA as $element) {
/** @psalm-suppress ImpureFunctionCall */
$ret = $f($element, $ret);
}
Expand Down

0 comments on commit 8fc58a4

Please sign in to comment.