Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit ff8eba5

Browse files
committed
Merge pull request #64 from hdgarrood/bug-63
Fix for issue #63
2 parents 8460f3d + 6842f5d commit ff8eba5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Data/StrMap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ exports._foldM = function (bind) {
4747
return function (f) {
4848
return function (mz) {
4949
return function (m) {
50+
var acc = mz;
5051
function g(k) {
5152
return function (z) {
5253
return f(z)(k)(m[k]);
5354
};
5455
}
5556
for (var k in m) {
5657
if (m.hasOwnProperty(k)) {
57-
mz = bind(mz)(g(k));
58+
acc = bind(acc)(g(k));
5859
}
5960
}
60-
return mz;
61+
return acc;
6162
};
6263
};
6364
};

test/Test/Data/StrMap.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,12 @@ strMapTests = do
143143

144144
log "fromFoldable = zip keys values"
145145
quickCheck $ \(TestStrMap m) -> M.toList m == zipWith Tuple (fromFoldable $ M.keys m) (M.values m :: List Int)
146+
147+
log "Bug #63: accidental observable mutation in foldMap"
148+
quickCheck \(TestStrMap m) ->
149+
let lhs = go m
150+
rhs = go m
151+
in lhs == rhs <?> ("lhs: " <> show lhs <> ", rhs: " <> show rhs)
152+
where
153+
go :: M.StrMap (Array Ordering) -> Array Ordering
154+
go = M.foldMap \_ v -> v

0 commit comments

Comments
 (0)