Skip to content

Commit ca87c46

Browse files
Cootpaf31
authored andcommitted
Fix #67: use purescript-record (#68)
1 parent c34b3bb commit ca87c46

File tree

2 files changed

+4
-41
lines changed

2 files changed

+4
-41
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"purescript-sets": "^3.0.0",
2020
"purescript-unsafe-coerce": "^3.0.0",
2121
"purescript-transformers": "^3.0.0",
22-
"purescript-symbols": "^3.0.0"
22+
"purescript-record": "^0.2.0"
2323
},
2424
"devDependencies": {
2525
"purescript-console": "^3.0.0"

src/Data/Lens/Record.purs

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,10 @@
11
module Data.Lens.Record (prop) where
22

33
import Prelude
4-
import Data.StrMap as S
5-
import Data.Lens (Lens, lens)
6-
import Data.Maybe (fromJust)
7-
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
8-
import Partial.Unsafe (unsafePartial)
9-
import Unsafe.Coerce (unsafeCoerce)
10-
11-
unsafeGet
12-
:: forall r a
13-
. String
14-
-> Record r
15-
-> a
16-
unsafeGet s = unsafePartial fromJust <<< S.lookup s <<< unsafeCoerce
17-
18-
unsafeSet
19-
:: forall r1 r2 a
20-
. String
21-
-> a
22-
-> Record r1
23-
-> Record r2
24-
unsafeSet s a = unsafeCoerce <<< S.insert s a <<< unsafeCoerce
25-
26-
get
27-
:: forall r r' l a
28-
. IsSymbol l
29-
=> RowCons l a r' r
30-
=> SProxy l
31-
-> Record r
32-
-> a
33-
get l = unsafeGet (reflectSymbol l)
344

35-
set
36-
:: forall r1 r2 r l a b
37-
. IsSymbol l
38-
=> RowCons l a r r1
39-
=> RowCons l b r r2
40-
=> SProxy l
41-
-> b
42-
-> Record r1
43-
-> Record r2
44-
set l = unsafeSet (reflectSymbol l)
5+
import Data.Lens (Lens, lens)
6+
import Data.Record (get, set)
7+
import Data.Symbol (class IsSymbol, SProxy)
458

469
-- | Construct a (type-changing) lens for a record property, by providing a
4710
-- | proxy for the `Symbol` which corresponds to the property label.

0 commit comments

Comments
 (0)