mirror of
https://github.com/juspay/jrec.git
synced 2024-09-19 14:18:17 +03:00
Remove (:=:) alias
This commit is contained in:
parent
451841c9ea
commit
5badc49588
13
src/JRec.hs
13
src/JRec.hs
@ -5,11 +5,10 @@
|
||||
module JRec
|
||||
( Record,
|
||||
pattern Record,
|
||||
(:=:),
|
||||
pattern (:=:),
|
||||
pattern ExactRecord,
|
||||
unField,
|
||||
union,
|
||||
(:=)(..),
|
||||
)
|
||||
where
|
||||
|
||||
@ -24,7 +23,7 @@ import GHC.TypeLits
|
||||
import Generic.Data
|
||||
import qualified JRec.Super as R
|
||||
import Control.Lens ((&), (^.))
|
||||
import JRec.Super ((:=))
|
||||
import JRec.Super ((:=)(..))
|
||||
import JRec.Tuple
|
||||
import JRec.Field
|
||||
import Unsafe.Coerce
|
||||
@ -50,14 +49,6 @@ instance
|
||||
unField :: field ~ field' => R.FldProxy field -> (field' R.:= value) -> value
|
||||
unField _ (_ R.:= value) = value
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Aliases
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
type a :=: b = a := b
|
||||
|
||||
pattern a :=: b = a R.:= b
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Other operations
|
||||
----------------------------------------------------------------------------
|
||||
|
@ -7,37 +7,37 @@ import JRec
|
||||
spec :: Spec
|
||||
spec = do
|
||||
it "polymorphic" $ do
|
||||
(ExactRecord (#u :=: True, #a :=: 5, #b :=: 6) & #u .~ 5)
|
||||
`shouldBe` ExactRecord (#u :=: 5, #a :=: 5, #b :=: 6)
|
||||
(ExactRecord (#u := True, #a := 5, #b := 6) & #u .~ 5)
|
||||
`shouldBe` ExactRecord (#u := 5, #a := 5, #b := 6)
|
||||
it "show" $ do
|
||||
show (ExactRecord ()) `shouldBe` "{}"
|
||||
show (ExactRecord (#foo :=: True)) `shouldBe` "{foo = True}"
|
||||
show (ExactRecord (#foo :=: True, #bar :=: 0)) `shouldBe` "{foo = True, bar = 0}"
|
||||
show (ExactRecord (#foo := True)) `shouldBe` "{foo = True}"
|
||||
show (ExactRecord (#foo := True, #bar := 0)) `shouldBe` "{foo = True, bar = 0}"
|
||||
it "get" $ do
|
||||
let getA1 :: Record ("a" :=: Int ': rest) -> Int
|
||||
let getA1 :: Record ("a" := Int ': rest) -> Int
|
||||
getA1 = (^. #a)
|
||||
let getA2 :: Record ("u" :=: Bool ': "a" :=: Int ': rest) -> Int
|
||||
let getA2 :: Record ("u" := Bool ': "a" := Int ': rest) -> Int
|
||||
getA2 = (^. #a)
|
||||
getA1 (ExactRecord (#a :=: 5)) `shouldBe` 5
|
||||
getA1 (ExactRecord (#a :=: 5, #b :=: 6)) `shouldBe` 5
|
||||
getA2 (ExactRecord (#u :=: True, #a :=: 5)) `shouldBe` 5
|
||||
getA2 (ExactRecord (#u :=: True, #a :=: 5, #b :=: 6)) `shouldBe` 5
|
||||
getA1 (ExactRecord (#a := 5)) `shouldBe` 5
|
||||
getA1 (ExactRecord (#a := 5, #b := 6)) `shouldBe` 5
|
||||
getA2 (ExactRecord (#u := True, #a := 5)) `shouldBe` 5
|
||||
getA2 (ExactRecord (#u := True, #a := 5, #b := 6)) `shouldBe` 5
|
||||
it "set" $ do
|
||||
let setA1 ::
|
||||
Record ("a" :=: Int ': rest) ->
|
||||
Record ("a" :=: Int ': rest)
|
||||
Record ("a" := Int ': rest) ->
|
||||
Record ("a" := Int ': rest)
|
||||
setA1 = (#a .~ 8)
|
||||
let setA2 ::
|
||||
Record ("u" :=: Bool ': "a" :=: Int ': rest) ->
|
||||
Record ("u" :=: Bool ': "a" :=: Int ': rest)
|
||||
Record ("u" := Bool ': "a" := Int ': rest) ->
|
||||
Record ("u" := Bool ': "a" := Int ': rest)
|
||||
setA2 = (#a .~ 8)
|
||||
setA1 (ExactRecord (#a :=: 5))
|
||||
`shouldBe` (ExactRecord (#a :=: 8))
|
||||
setA1 (ExactRecord (#a :=: 5, #b :=: 6))
|
||||
`shouldBe` (ExactRecord (#a :=: 8, #b :=: 6))
|
||||
setA2 (ExactRecord (#u :=: True, #a :=: 5))
|
||||
`shouldBe` (ExactRecord (#u :=: True, #a :=: 8))
|
||||
setA2 (ExactRecord (#u :=: True, #a :=: 5, #b :=: 6))
|
||||
`shouldBe` (ExactRecord (#u :=: True, #a :=: 8, #b :=: 6))
|
||||
setA1 (ExactRecord (#a := 5))
|
||||
`shouldBe` (ExactRecord (#a := 8))
|
||||
setA1 (ExactRecord (#a := 5, #b := 6))
|
||||
`shouldBe` (ExactRecord (#a := 8, #b := 6))
|
||||
setA2 (ExactRecord (#u := True, #a := 5))
|
||||
`shouldBe` (ExactRecord (#u := True, #a := 8))
|
||||
setA2 (ExactRecord (#u := True, #a := 5, #b := 6))
|
||||
`shouldBe` (ExactRecord (#u := True, #a := 8, #b := 6))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user