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

Commit 8a31a5c

Browse files
committed
Merge pull request #43 from jbrownson/master
fix peek to return Maybe, update docs
2 parents 8579971 + e2f7974 commit 8a31a5c

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

docs/Data/Map.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ of duplicate keys
175175
#### `unions`
176176

177177
``` purescript
178-
unions :: forall k v. (Ord k) => List (Map k v) -> Map k v
178+
unions :: forall k v f. (Ord k, Foldable f) => f (Map k v) -> Map k v
179179
```
180180

181181
Compute the union of a collection of maps

docs/Data/StrMap/ST.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Create a new, empty mutable map
2727
#### `peek`
2828

2929
``` purescript
30-
peek :: forall a h r. STStrMap h a -> String -> Eff (st :: ST h | r) a
30+
peek :: forall a h r. STStrMap h a -> String -> Eff (st :: ST h | r) (Maybe a)
3131
```
3232

3333
Get the value for a key in a mutable map

src/Data/StrMap/ST.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ exports["new"] = function () {
77
return {};
88
};
99

10-
exports.peek = function (m) {
11-
return function (k) {
12-
return function () {
13-
return m[k];
10+
exports.peekImpl = function (just) {
11+
return function (nothing) {
12+
return function (m) {
13+
return function (k) {
14+
return function () {
15+
return {}.hasOwnProperty.call(m, k) ? just(m[k]) : nothing;
16+
};
17+
};
1418
};
1519
};
1620
};

src/Data/StrMap/ST.purs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Prelude
1414

1515
import Control.Monad.Eff (Eff())
1616
import Control.Monad.ST (ST())
17+
import Data.Maybe (Maybe(..))
1718

1819
-- | A reference to a mutable map
1920
-- |
@@ -26,7 +27,10 @@ foreign import data STStrMap :: * -> * -> *
2627
foreign import new :: forall a h r. Eff (st :: ST h | r) (STStrMap h a)
2728

2829
-- | Get the value for a key in a mutable map
29-
foreign import peek :: forall a h r. STStrMap h a -> String -> Eff (st :: ST h | r) a
30+
peek :: forall a h r. STStrMap h a -> String -> Eff (st :: ST h | r) (Maybe a)
31+
peek = peekImpl Just Nothing
32+
33+
foreign import peekImpl :: forall a b h r. (a -> b) -> b -> STStrMap h a -> String -> Eff (st :: ST h | r) b
3034

3135
-- | Update the value for a key in a mutable map
3236
foreign import poke :: forall a h r. STStrMap h a -> String -> a -> Eff (st :: ST h | r) (STStrMap h a)

0 commit comments

Comments
 (0)