Skip to content

deprecate verbose ST function names #36

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
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
10 changes: 5 additions & 5 deletions src/Data/Record/ST.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ function copyRecord(rec) {
return copy;
}

exports.runSTRecord = function(rec) {
exports.run = function(rec) {
return function() {
return copyRecord(rec());
};
};

exports.freezeSTRecord = function(rec) {
exports.freeze = function(rec) {
return function() {
return copyRecord(rec);
};
};

exports.thawSTRecord = function(rec) {
exports.thaw = function(rec) {
return function() {
return copyRecord(rec);
};
};

exports.unsafePeekSTRecord = function(l) {
exports.unsafePeek = function(l) {
return function(rec) {
return function() {
return rec[l];
};
};
};

exports.unsafePokeSTRecord = function(l) {
exports.unsafePoke = function(l) {
return function(a) {
return function(rec) {
return function() {
Expand Down
69 changes: 58 additions & 11 deletions src/Data/Record/ST.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module Data.Record.ST
( STRecord
, freeze
, thaw
, peek
, poke
, run
, pureSTRecord

-- deprecated
, freezeSTRecord
, thawSTRecord
, peekSTRecord
, pokeSTRecord
, runSTRecord
, pureSTRecord
) where

import Prelude
Expand All @@ -21,37 +28,37 @@ import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
foreign import data STRecord :: Type -> # Type -> Type

-- | Freeze a mutable record, creating a copy.
foreign import freezeSTRecord :: forall h r eff. STRecord h r -> Eff (st :: ST h | eff) (Record r)
foreign import freeze :: forall h r eff. STRecord h r -> Eff (st :: ST h | eff) (Record r)

-- | Thaw an immutable record, creating a copy.
foreign import thawSTRecord :: forall h r eff. Record r -> Eff (st :: ST h | eff) (STRecord h r)
foreign import thaw :: forall h r eff. Record r -> Eff (st :: ST h | eff) (STRecord h r)

-- | Run an ST computation safely, constructing a record.
foreign import runSTRecord :: forall r eff. (forall h. Eff (st :: ST h | eff) (STRecord h r)) -> Eff eff (Record r)
foreign import run :: forall r eff. (forall h. Eff (st :: ST h | eff) (STRecord h r)) -> Eff eff (Record r)

-- | Run an ST computation safely, constructing a record, assuming no other
-- | types of effects.
pureSTRecord :: forall r. (forall h eff. Eff (st :: ST h | eff) (STRecord h r)) -> Record r
pureSTRecord st = runPure (runSTRecord st)
pureSTRecord st = runPure (run st)

foreign import unsafePeekSTRecord
foreign import unsafePeek
:: forall a r h eff
. String
-> STRecord h r
-> Eff (st :: ST h | eff) 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.
peekSTRecord
peek
:: forall l h a r r1 eff
. RowCons l a r1 r
=> IsSymbol l
=> SProxy l
-> STRecord h r
-> Eff (st :: ST h | eff) a
peekSTRecord l = unsafePeekSTRecord (reflectSymbol l)
peek l = unsafePeek (reflectSymbol l)

foreign import unsafePokeSTRecord
foreign import unsafePoke
:: forall a r h eff
. String
-> a
Expand All @@ -60,12 +67,52 @@ foreign import unsafePokeSTRecord

-- | Modify a record in place, by providing a type-level representative for the label
-- | which should be updated.
pokeSTRecord
poke
:: forall l h a r r1 eff
. RowCons l a r1 r
=> IsSymbol l
=> SProxy l
-> a
-> STRecord h r
-> Eff (st :: ST h | eff) Unit
pokeSTRecord l = unsafePokeSTRecord (reflectSymbol l)
poke l = unsafePoke (reflectSymbol l)

freezeSTRecord
:: forall h r eff
. Warn "Deprecated `freezeSTRecord`. Use `freeze` instead."
=> STRecord h r -> Eff (st :: ST h | eff) (Record r)
freezeSTRecord = freeze

thawSTRecord
:: forall h r eff
. Warn "Deprecated `thawSTRecord`. Use `thaw` instead."
=> Record r -> Eff (st :: ST h | eff) (STRecord h r)
thawSTRecord = thaw

peekSTRecord
:: forall l h a r r1 eff
. Warn "Deprecated `peekSTRecord`. Use `peek` instead."
=> RowCons l a r1 r
=> IsSymbol l
=> SProxy l
-> STRecord h r
-> Eff (st :: ST h | eff) a
peekSTRecord = peek

pokeSTRecord
:: forall l h a r r1 eff
. Warn "Deprecated `pokeSTRecord`. Use `poke` instead."
=> RowCons l a r1 r
=> IsSymbol l
=> SProxy l
-> a
-> STRecord h r
-> Eff (st :: ST h | eff) Unit
pokeSTRecord = poke

runSTRecord
:: forall r eff
. Warn "Deprecated `runSTRecord`. Use `run` instead."
=> (forall h. Eff (st :: ST h | eff) (STRecord h r))
-> Eff eff (Record r)
runSTRecord = run
10 changes: 5 additions & 5 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Prelude
import Control.Monad.Eff (Eff)
import Data.Record (delete, equal, get, insert, modify, rename, set)
import Data.Record.Builder as Builder
import Data.Record.ST (pokeSTRecord, pureSTRecord, thawSTRecord)
import Data.Record.ST (poke, pureSTRecord, thaw)
import Data.Record.Unsafe (unsafeHas)
import Data.Symbol (SProxy(..))
import Test.Assert (ASSERT, assert')
Expand Down Expand Up @@ -38,12 +38,12 @@ main = do
not $ unsafeHas "b" { a: 42 }

let stTest1 = pureSTRecord do
rec <- thawSTRecord { x: 41, y: "" }
pokeSTRecord x 42 rec
pokeSTRecord y "testing" rec
rec <- thaw { x: 41, y: "" }
poke x 42 rec
poke y "testing" rec
pure rec

assert' "pokeSTRecord" $
assert' "poke" $
stTest1.x == 42 && stTest1.y == "testing"

let testBuilder = Builder.build (Builder.insert x 42
Expand Down