Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.
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
26 changes: 8 additions & 18 deletions src/Data/StrMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@

// module Data.StrMap

exports._copy = function (m) {
var r = {};
for (var k in m) {
if (m.hasOwnProperty(k)) {
r[k] = m[k];
}
}
return r;
};

exports._copyEff = function (m) {
return function () {
var r = {};
for (var k in m) {
if (m.hasOwnProperty(k)) {
if (hasOwnProperty.call(m, k)) {
r[k] = m[k];
}
}
Expand All @@ -35,7 +25,7 @@ exports.runST = function (f) {
exports._fmapStrMap = function (m0, f) {
var m = {};
for (var k in m0) {
if (m0.hasOwnProperty(k)) {
if (hasOwnProperty.call(m0, k)) {
m[k] = f(m0[k]);
}
}
Expand All @@ -46,7 +36,7 @@ exports._fmapStrMap = function (m0, f) {
exports._mapWithKey = function (m0, f) {
var m = {};
for (var k in m0) {
if (m0.hasOwnProperty(k)) {
if (hasOwnProperty.call(m0, k)) {
m[k] = f(k)(m0[k]);
}
}
Expand All @@ -65,7 +55,7 @@ exports._foldM = function (bind) {
};
}
for (var k in m) {
if (m.hasOwnProperty(k)) {
if (hasOwnProperty.call(m, k)) {
acc = bind(acc)(g(k));
}
}
Expand All @@ -78,7 +68,7 @@ exports._foldM = function (bind) {
// jshint maxparams: 4
exports._foldSCStrMap = function (m, z, f, fromMaybe) {
for (var k in m) {
if (m.hasOwnProperty(k)) {
if (hasOwnProperty.call(m, k)) {
var maybeR = f(z)(k)(m[k]);
var r = fromMaybe(null)(maybeR);
if (r === null) return z;
Expand All @@ -92,7 +82,7 @@ exports._foldSCStrMap = function (m, z, f, fromMaybe) {
exports.all = function (f) {
return function (m) {
for (var k in m) {
if (m.hasOwnProperty(k) && !f(k)(m[k])) return false;
if (hasOwnProperty.call(m, k) && !f(k)(m[k])) return false;
}
return true;
};
Expand All @@ -101,7 +91,7 @@ exports.all = function (f) {
exports.size = function (m) {
var s = 0;
for (var k in m) {
if (m.hasOwnProperty(k)) {
if (hasOwnProperty.call(m, k)) {
++s;
}
}
Expand Down Expand Up @@ -130,7 +120,7 @@ function _collect(f) {
return function (m) {
var r = [];
for (var k in m) {
if (m.hasOwnProperty(k)) {
if (hasOwnProperty.call(m, k)) {
r.push(f(k)(m[k]));
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Data/StrMap.purs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ import Data.Unfoldable (class Unfoldable)
-- | `StrMap a` represents a map from `String`s to values of type `a`.
foreign import data StrMap :: * -> *

foreign import _copy :: forall a. StrMap a -> StrMap a

foreign import _copyEff :: forall a b h r. a -> Eff (st :: ST.ST h | r) b

-- | Convert an immutable map into a mutable map
Expand Down
4 changes: 3 additions & 1 deletion test/Test/Data/StrMap.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Partial.Unsafe (unsafePartial)

import Test.QuickCheck ((<?>), quickCheck, quickCheck', (===))
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary)
import Test.QuickCheck.Gen as Gen

newtype TestStrMap v = TestStrMap (M.StrMap v)

Expand All @@ -34,7 +35,8 @@ instance showInstruction :: (Show k, Show v) => Show (Instruction k v) where
instance arbInstruction :: (Arbitrary v) => Arbitrary (Instruction String v) where
arbitrary = do
b <- arbitrary
k <- arbitrary
k <- Gen.frequency (Tuple 10.0 (pure "hasOwnProperty"))
(Tuple 50.0 arbitrary `Cons` Nil)
case b of
true -> do
v <- arbitrary
Expand Down