Skip to content

classes from @doolse's purescript-records: #7

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

Closed
wants to merge 2 commits into from
Closed
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
111 changes: 0 additions & 111 deletions src/Data/Record.purs

This file was deleted.

8 changes: 8 additions & 0 deletions src/Data/Record/Class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";

exports.unsafeMerge = function (l) {
return function (r) {
var o = {};
return Object.assign(o, l, r);
};
};
51 changes: 51 additions & 0 deletions src/Data/Record/Class.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Data.Record.Class (
class Subrow,
class RecordMerge,
class IntersectRow,
merge,
unionMerge
) where

-- | Proof that row `r` is a subset of row `s`
class Subrow (r :: # Type) (s :: # Type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just use Union directly here.

instance srInst :: Union r t s => Subrow r s

-- | Proof of row `i` being the intersection of rows `ri` and `si`,
-- | `r` is `i` subtracted from `ri` and
-- | `s` is `i` subtracted from `si`
class IntersectRow (ri :: # Type) (si :: # Type) (i :: # Type) (r :: # Type) (s :: # Type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really belongs in typelevel-prelude since it's not record specific.

instance irInst :: (Union r i ri, Union i s si) => IntersectRow ri si i r s

class RecordMerge (o :: # Type) (mr :: # Type) (mo :: # Type)
instance rmInst :: (IntersectRow mo mr m o r, Subrow r o) => RecordMerge o mr mo


-- | Merge any two records together unsafely.
-- | Fields common between the two will result in the value from r2 being kept
foreign import unsafeMerge
:: forall r1 r2 r3
. Record r1
-> Record r2
-> Record r3

-- | Merge a record `mr` with optional default values `o`, resulting in record `mo`.
-- |
-- | The record `mr` must consist of the common fields from `mo` and `mr` plus a subset
-- | of fields from `o`.
-- |
-- | Examples:
-- | * `merge {a:1,b:"Unspecified"} {a:3,c:"Mandatory"} = {a:3,b:"Unspecified",c:"Mandatory"}`
-- | * `merge {a:1,b:"Unspecified"} {c:"Only mandatory"} = {a:1,b:"Unspecified",c:"Only Mandatory"}`
-- | * `merge {a:1,b:"Unspecified"} {a:"Wrong type"} = wont compile`
merge :: forall o mr mo. RecordMerge o mr mo => Record o -> Record mr -> Record mo
merge = unsafeMerge

-- | Merge record `a` with `b` resulting in `c`. The `Union` constraint means that `c`
-- | will contain all the fields from both `a` and `b`, with `b`'s appearing first in the
-- | list of types.
-- |
-- | Examples:
-- | * `unionMerge {a:"Default"} {a:1} = {a:1} :: {a::Int,a::String}`
-- | * `unionMerge {a:"Default",b:2} {a:1} = {a:1,b:2} :: {a::Int,a::String,b::Int}`
unionMerge :: forall a b c. Union b a c => Record a -> Record b -> Record c
unionMerge = unsafeMerge
26 changes: 0 additions & 26 deletions src/Data/Record/Unsafe.js

This file was deleted.

23 changes: 0 additions & 23 deletions src/Data/Record/Unsafe.purs

This file was deleted.