From 295f73bba8b359351f8db67943edcdda5e1f10eb Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Wed, 17 Feb 2021 21:51:06 +0100 Subject: [PATCH] Remove Record.ST --- CHANGELOG.md | 2 +- src/Record/ST.js | 59 ---------------------------- src/Record/ST.purs | 95 ---------------------------------------------- test/Main.purs | 16 -------- 4 files changed, 1 insertion(+), 171 deletions(-) delete mode 100644 src/Record/ST.js delete mode 100644 src/Record/ST.purs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a1807f..49d278a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,10 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: - Added support for PureScript 0.14 and dropped support for all previous versions (#66) - Updated `Record.Builder.merge` and `Record.Builder.union` so that they behave like `Record.merge` and `Record.union`: fields from the argument override those of the record being built in case of overlaps. (#73) +- Removed `Record.ST` (#78) New features: - Added `buildFromScratch` for building from an empty record (#53) -- Added `new` and `run` to `Record.ST` (#71) - Added `flip` function (#73) Bugfixes: diff --git a/src/Record/ST.js b/src/Record/ST.js deleted file mode 100644 index 4ea7d15..0000000 --- a/src/Record/ST.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; - -exports.run = function (f) { - return f(); -}; - -exports["new"] = function () { - return {}; -}; - -function copyRecord(rec) { - var copy = {}; - for (var key in rec) { - if ({}.hasOwnProperty.call(rec, key)) { - copy[key] = rec[key]; - } - } - return copy; -} - -exports.freeze = function(rec) { - return function() { - return copyRecord(rec); - }; -}; - -exports.thaw = function(rec) { - return function() { - return copyRecord(rec); - }; -}; - -exports.unsafePeek = function(l) { - return function(rec) { - return function() { - return rec[l]; - }; - }; -}; - -exports.unsafePoke = function(l) { - return function(a) { - return function(rec) { - return function() { - rec[l] = a; - }; - }; - }; -}; - -exports.unsafeModify = function(l) { - return function(f) { - return function(rec) { - return function() { - rec[l] = f(rec[l]); - }; - }; - }; -}; diff --git a/src/Record/ST.purs b/src/Record/ST.purs deleted file mode 100644 index b078723..0000000 --- a/src/Record/ST.purs +++ /dev/null @@ -1,95 +0,0 @@ -module Record.ST - ( STRecord - , run - , new - , freeze - , thaw - , peek - , poke - , modify - ) where - -import Prelude - -import Control.Monad.ST (ST, Region) -import Data.Symbol (class IsSymbol, reflectSymbol) -import Prim.Row as Row - --- | A value of type `STRecord h r` represents a mutable record with fields `r`, --- | belonging to the state thread `h`. --- | --- | Create values of type `STRecord` using `thaw`. -foreign import data STRecord :: Region -> Row Type -> Type - -type role STRecord nominal representational - --- | Freeze a mutable record, creating an immutable record. Use this function as you would use --- | `Control.Monad.ST.run` (from the `purescript-st` package) to freeze a mutable reference. --- | --- | The rank-2 type prevents the record from escaping the scope of `run`. -foreign import run :: forall r. (forall h. ST h (STRecord h r)) -> Record r - --- | Create a new, empty mutable record -foreign import new :: forall h. ST h (STRecord h ()) - --- | Freeze a mutable record, creating a copy. -foreign import freeze :: forall h r. STRecord h r -> ST h (Record r) - --- | Thaw an immutable record, creating a copy. -foreign import thaw :: forall h r. Record r -> ST h (STRecord h r) - -foreign import unsafePeek - :: forall a r h - . String - -> STRecord h r - -> ST h a - --- | Read the current value of a field in a mutable record, by providing a --- | type-level representative for the label which should be read. -peek - :: forall proxy l h a r r1 - . Row.Cons l a r1 r - => IsSymbol l - => proxy l - -> STRecord h r - -> ST h a -peek l = unsafePeek (reflectSymbol l) - -foreign import unsafePoke - :: forall a r h - . String - -> a - -> STRecord h r - -> ST h Unit - --- | Modify a record in place, by providing a type-level representative for the label --- | which should be updated. -poke - :: forall proxy l h a r r1 - . Row.Cons l a r1 r - => IsSymbol l - => proxy l - -> a - -> STRecord h r - -> ST h Unit -poke l = unsafePoke (reflectSymbol l) - -foreign import unsafeModify - :: forall a r h - . String - -> (a -> a) - -> STRecord h r - -> ST h Unit - --- | Modify a record in place, --- | by providing a type-level representative for the label to update --- | and a function to update it. -modify - :: forall proxy l h a r r1 - . Row.Cons l a r1 r - => IsSymbol l - => proxy l - -> (a -> a) - -> STRecord h r - -> ST h Unit -modify l = unsafeModify (reflectSymbol l) diff --git a/test/Main.purs b/test/Main.purs index e98e5e1..124f3cd 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -5,7 +5,6 @@ import Prelude import Effect (Effect) import Record (delete, equal, get, insert, merge, modify, rename, set) import Record.Builder as Builder -import Record.ST (run, poke, thaw, modify) as ST import Record.Unsafe (unsafeHas) import Test.Assert (assert') import Type.Proxy (Proxy(..)) @@ -39,21 +38,6 @@ main = do assert' "unsafeHas2" $ not $ unsafeHas "b" { a: 42 } - let - stTest1 = ST.run do - rec <- ST.thaw { x: 41, y: "" } - ST.poke x 42 rec - ST.poke y "testing" rec - pure rec - stTest2 = ST.run do - rec <- ST.thaw { x: 41 } - ST.modify x (_ + 1) rec - pure rec - - assert' "pokeSTRecord" $ - stTest1.x == 42 && stTest1.y == "testing" - assert' "ST.modify" $ stTest2.x == 42 - let testBuilder = Builder.build (Builder.insert x 42 >>> Builder.merge { y: true, z: "testing" } >>> Builder.delete y