Skip to content

Update to v0.15.0 #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
6 changes: 2 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"parserOptions": {
"ecmaVersion": 5
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": "eslint:recommended",
"env": {
"commonjs": true
},
"rules": {
"strict": [2, "global"],
"block-scoped-var": 2,
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- uses: actions/checkout@v2

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"

- uses: actions/setup-node@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Notable changes to this project are documented in this file. The format is based
## [Unreleased]

Breaking changes:
- Migrate FFI to ES modules (#81 by @kl0tl and @JordanMartinez)
- Replaced polymorphic proxies with monomorphic `Proxy` (#81 by @JordanMartinez)

New features:

Expand Down
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"package.json"
],
"dependencies": {
"purescript-functions": "^5.0.0",
"purescript-prelude": "^5.0.0",
"purescript-unsafe-coerce": "^5.0.0"
"purescript-functions": "master",
"purescript-prelude": "master",
"purescript-unsafe-coerce": "master"
},
"devDependencies": {
"purescript-assert": "^5.0.0"
"purescript-assert": "master"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"devDependencies": {
"eslint": "^7.15.0",
"purescript-psa": "^0.8.0",
"pulp": "^15.0.0",
"purescript-psa": "^0.8.2",
"pulp": "16.0.0-0",
"rimraf": "^3.0.2"
}
}
28 changes: 14 additions & 14 deletions src/Record.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import Unsafe.Coerce (unsafeCoerce)
-- | get (Proxy :: Proxy "x") :: forall r a. { x :: a | r } -> a
-- | ```
get
:: forall proxy r r' l a
:: forall r r' l a
. IsSymbol l
=> Cons l a r' r
=> proxy l
=> Proxy l
-> Record r
-> a
get l r = unsafeGet (reflectSymbol l) r
Expand All @@ -52,11 +52,11 @@ get l r = unsafeGet (reflectSymbol l) r
-- | :: forall r a b. a -> { x :: b | r } -> { x :: a | r }
-- | ```
set
:: forall proxy r1 r2 r l a b
:: forall r1 r2 r l a b
. IsSymbol l
=> Cons l a r r1
=> Cons l b r r2
=> proxy l
=> Proxy l
-> b
-> Record r1
-> Record r2
Expand All @@ -72,11 +72,11 @@ set l b r = unsafeSet (reflectSymbol l) b r
-- | :: forall r a b. (a -> b) -> { x :: a | r } -> { x :: b | r }
-- | ```
modify
:: forall proxy r1 r2 r l a b
:: forall r1 r2 r l a b
. IsSymbol l
=> Cons l a r r1
=> Cons l b r r2
=> proxy l
=> Proxy l
-> (a -> b)
-> Record r1
-> Record r2
Expand All @@ -92,11 +92,11 @@ modify l f r = set l (f (get l r)) r
-- | :: forall r a. Lacks "x" r => a -> { | r } -> { x :: a | r }
-- | ```
insert
:: forall proxy r1 r2 l a
:: forall r1 r2 l a
. IsSymbol l
=> Lacks l r1
=> Cons l a r1 r2
=> proxy l
=> Proxy l
-> a
-> Record r1
-> Record r2
Expand All @@ -115,11 +115,11 @@ insert l a r = unsafeSet (reflectSymbol l) a r
-- | :: forall r a. Lacks "x" r => { x :: a | r } -> { | r }
-- | ```
delete
:: forall proxy r1 r2 l a
:: forall r1 r2 l a
. IsSymbol l
=> Lacks l r1
=> Cons l a r1 r2
=> proxy l
=> Proxy l
-> Record r2
-> Record r1
delete l r = unsafeDelete (reflectSymbol l) r
Expand All @@ -136,15 +136,15 @@ delete l r = unsafeDelete (reflectSymbol l) r
-- | rename (Proxy :: Proxy "x") (Proxy :: Proxy "y")
-- | :: forall a r. Lacks "x" r => Lacks "y" r => { x :: a | r} -> { y :: a | r}
-- | ```
rename :: forall proxy prev next ty input inter output
rename :: forall prev next ty input inter output
. IsSymbol prev
=> IsSymbol next
=> Cons prev ty inter input
=> Lacks prev inter
=> Cons next ty inter output
=> Lacks next inter
=> proxy prev
-> proxy next
=> Proxy prev
-> Proxy next
-> Record input
-> Record output
rename prev next record =
Expand Down Expand Up @@ -224,7 +224,7 @@ equal
equal a b = equalFields (Proxy :: Proxy rs) a b

class EqualFields (rs :: RowList Type) (row :: Row Type) | rs -> row where
equalFields :: forall rlproxy. rlproxy rs -> Record row -> Record row -> Boolean
equalFields :: Proxy rs -> Record row -> Record row -> Boolean

instance equalFieldsCons
::
Expand Down
22 changes: 10 additions & 12 deletions src/Record/Builder.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
"use strict";

exports.copyRecord = function(rec) {
export function copyRecord(rec) {
var copy = {};
for (var key in rec) {
if ({}.hasOwnProperty.call(rec, key)) {
copy[key] = rec[key];
}
}
return copy;
};
}

exports.unsafeInsert = function(l) {
export function unsafeInsert(l) {
return function(a) {
return function(rec) {
rec[l] = a;
return rec;
};
};
};
}

exports.unsafeModify = function(l) {
export function unsafeModify(l) {
return function (f) {
return function(rec) {
rec[l] = f(rec[l]);
return rec;
};
};
};
}

exports.unsafeDelete = function(l) {
export function unsafeDelete(l) {
return function(rec) {
delete rec[l];
return rec;
};
};
}

exports.unsafeRename = function(l1) {
export function unsafeRename(l1) {
return function (l2) {
return function (rec) {
rec[l2] = rec[l1];
delete rec[l1];
return rec;
};
};
};
}
19 changes: 10 additions & 9 deletions src/Record/Builder.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Function.Uncurried (runFn2)
import Data.Symbol (class IsSymbol, reflectSymbol)
import Prim.Row as Row
import Record.Unsafe.Union (unsafeUnionFn)
import Type.Proxy (Proxy)
import Unsafe.Coerce (unsafeCoerce)

foreign import copyRecord :: forall r1. Record r1 -> Record r1
Expand Down Expand Up @@ -61,46 +62,46 @@ derive newtype instance categoryBuilder :: Category Builder

-- | Build by inserting a new field.
insert
:: forall proxy l a r1 r2
:: forall l a r1 r2
. Row.Cons l a r1 r2
=> Row.Lacks l r1
=> IsSymbol l
=> proxy l
=> Proxy l
-> a
-> Builder (Record r1) (Record r2)
insert l a = Builder \r1 -> unsafeInsert (reflectSymbol l) a r1

-- | Build by modifying an existing field.
modify
:: forall proxy l a b r r1 r2
:: forall l a b r r1 r2
. Row.Cons l a r r1
=> Row.Cons l b r r2
=> IsSymbol l
=> proxy l
=> Proxy l
-> (a -> b)
-> Builder (Record r1) (Record r2)
modify l f = Builder \r1 -> unsafeModify (reflectSymbol l) f r1

-- | Build by deleting an existing field.
delete
:: forall proxy l a r1 r2
:: forall l a r1 r2
. IsSymbol l
=> Row.Lacks l r1
=> Row.Cons l a r1 r2
=> proxy l
=> Proxy l
-> Builder (Record r2) (Record r1)
delete l = Builder \r2 -> unsafeDelete (reflectSymbol l) r2

-- | Build by renaming an existing field.
rename :: forall proxy l1 l2 a r1 r2 r3
rename :: forall l1 l2 a r1 r2 r3
. IsSymbol l1
=> IsSymbol l2
=> Row.Cons l1 a r2 r1
=> Row.Lacks l1 r2
=> Row.Cons l2 a r2 r3
=> Row.Lacks l2 r2
=> proxy l1
-> proxy l2
=> Proxy l1
-> Proxy l2
-> Builder (Record r1) (Record r3)
rename l1 l2 = Builder \r1 -> unsafeRename (reflectSymbol l1) (reflectSymbol l2) r1

Expand Down
6 changes: 2 additions & 4 deletions src/Record/Unsafe/Union.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use strict";

exports.unsafeUnionFn = function(r1, r2) {
export function unsafeUnionFn(r1, r2) {
var copy = {};
for (var k1 in r2) {
if ({}.hasOwnProperty.call(r2, k1)) {
Expand All @@ -13,4 +11,4 @@ exports.unsafeUnionFn = function(r1, r2) {
}
}
return copy;
};
}