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

Commit 757a077

Browse files
committed
add tests + docs
1 parent c5cdcfe commit 757a077

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
singleton :: forall k v. k -> v -> Map k v
5050

51+
size :: forall k v. Map k v -> Number
52+
5153
toList :: forall k v. Map k v -> [Tuple k v]
5254

5355
union :: forall k v. (P.Ord k) => Map k v -> Map k v -> Map k v

src/Data/Map.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module Data.Map
2323
values,
2424
union,
2525
unions,
26-
map
26+
map,
27+
size
2728
) where
2829

2930
import qualified Prelude as P

tests/Data/Map.purs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Debug.Trace
44

55
import Data.Maybe
66
import Data.Tuple
7-
import Data.Array (map)
7+
import Data.Array (map, length, nubBy)
88
import Data.Function (on)
99
import Data.Foldable (foldl)
1010

@@ -165,3 +165,8 @@ mapTests = do
165165

166166
trace "Union is idempotent"
167167
quickCheck $ \m1 m2 -> (m1 `M.union` m2) == ((m1 `M.union` m2) `M.union` (m2 :: M.Map SmallKey Number))
168+
169+
trace "size"
170+
quickCheck $ \xs ->
171+
let xs' = nubBy ((==) `on` fst) xs
172+
in M.size (M.fromList xs') == length (xs' :: [Tuple SmallKey Number])

0 commit comments

Comments
 (0)