Created
October 28, 2019 00:22
-
-
Save MonoidMusician/37b3923462340c4c9293443b2170341d to your computer and use it in GitHub Desktop.
Append records on their overlap (assuming only the overlap has `Semigroup`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test.AppendOverlap where | |
import Data.Semigroup (class Semigroup, (<>)) | |
import Data.Tuple (Tuple(..)) | |
import Prim.Row (class Nub, class Union) | |
import Record (union) | |
import Unsafe.Coerce (unsafeCoerce) | |
unsafeSplit :: | |
forall left right nubbed. | |
Union left right nubbed => | |
Nub nubbed nubbed => | |
Record nubbed -> Tuple (Record left) (Record right) | |
unsafeSplit r = Tuple (unsafeCoerce r) (unsafeCoerce r) | |
appendOverlapPt2 :: | |
forall left leftUniq right rightUniq both nubbed duped. | |
Nub left left => | |
Nub right right => | |
Union left right both => | |
Nub both nubbed => | |
Union duped nubbed both => | |
Union duped leftUniq left => | |
Union duped rightUniq right => | |
Union left rightUniq nubbed => | |
Semigroup (Record duped) => | |
Record left -> Record right -> Record nubbed | |
appendOverlapPt2 left right = | |
let | |
Tuple dupedL (leftUniq :: Record leftUniq) = unsafeSplit left | |
Tuple dupedR (rightUniq :: Record rightUniq) = unsafeSplit right | |
duped = (dupedL <> dupedR) :: Record duped | |
(merge1 :: Record left) = union duped leftUniq | |
(merge2 :: Record nubbed) = union merge1 rightUniq | |
in merge2 | |
test = { foo: 1, bar: "Hello" } `appendOverlapPt2` { bar: ", World", baz: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment