{-# OPTIONS_GHC -Wno-orphans #-}
module PlutusLedgerApi.Orphans.Common (
Blake2b256Hash (..),
Blake2b244Hash (..),
getBlake2b256Hash,
getBlake2b244Hash,
UnsortedAssocMap,
getUnsortedAssocMap,
) where
import Data.ByteString (ByteString)
import Data.Coerce (coerce)
import Data.Kind (Type)
import Data.Set qualified as Set
import PlutusLedgerApi.QuickCheck.Utils (unSizedByteString)
import PlutusPrelude (Pretty)
import PlutusTx.AssocMap qualified as AssocMap
import PlutusTx.Builtins qualified as Builtins
import PlutusTx.Prelude qualified as PlutusTx
import Test.QuickCheck (
Arbitrary (arbitrary, shrink),
Arbitrary1 (liftArbitrary, liftShrink),
CoArbitrary (coarbitrary),
Function (function),
Gen,
NonNegative (NonNegative),
functionMap,
getNonNegative,
liftArbitrary,
oneof,
scale,
shuffle,
sized,
variant,
)
instance Arbitrary PlutusTx.BuiltinByteString where
{-# INLINEABLE arbitrary #-}
arbitrary :: Gen BuiltinByteString
arbitrary = forall a. HasToBuiltin a => a -> ToBuiltin a
PlutusTx.toBuiltin @ByteString (ByteString -> BuiltinByteString)
-> Gen ByteString -> Gen BuiltinByteString
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ByteString
forall a. Arbitrary a => Gen a
arbitrary
{-# INLINEABLE shrink #-}
shrink :: BuiltinByteString -> [BuiltinByteString]
shrink = (ByteString -> BuiltinByteString)
-> [ByteString] -> [BuiltinByteString]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. HasToBuiltin a => a -> ToBuiltin a
PlutusTx.toBuiltin @ByteString) ([ByteString] -> [BuiltinByteString])
-> (BuiltinByteString -> [ByteString])
-> BuiltinByteString
-> [BuiltinByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [ByteString]
forall a. Arbitrary a => a -> [a]
shrink (ByteString -> [ByteString])
-> (BuiltinByteString -> ByteString)
-> BuiltinByteString
-> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinByteString -> ByteString
BuiltinByteString -> FromBuiltin BuiltinByteString
forall arep. HasFromBuiltin arep => arep -> FromBuiltin arep
PlutusTx.fromBuiltin
instance CoArbitrary PlutusTx.BuiltinByteString where
{-# INLINEABLE coarbitrary #-}
coarbitrary :: forall b. BuiltinByteString -> Gen b -> Gen b
coarbitrary = ByteString -> Gen b -> Gen b
forall b. ByteString -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary (ByteString -> Gen b -> Gen b)
-> (BuiltinByteString -> ByteString)
-> BuiltinByteString
-> Gen b
-> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinByteString -> ByteString
BuiltinByteString -> FromBuiltin BuiltinByteString
forall arep. HasFromBuiltin arep => arep -> FromBuiltin arep
PlutusTx.fromBuiltin
instance Function PlutusTx.BuiltinByteString where
{-# INLINEABLE function #-}
function :: forall b. (BuiltinByteString -> b) -> BuiltinByteString :-> b
function = (BuiltinByteString -> ByteString)
-> (ByteString -> BuiltinByteString)
-> (BuiltinByteString -> b)
-> BuiltinByteString :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap BuiltinByteString -> ByteString
BuiltinByteString -> FromBuiltin BuiltinByteString
forall arep. HasFromBuiltin arep => arep -> FromBuiltin arep
PlutusTx.fromBuiltin (forall a. HasToBuiltin a => a -> ToBuiltin a
PlutusTx.toBuiltin @ByteString)
newtype Blake2b244Hash = Blake2b244Hash PlutusTx.BuiltinByteString
deriving (Blake2b244Hash -> Blake2b244Hash -> Bool
(Blake2b244Hash -> Blake2b244Hash -> Bool)
-> (Blake2b244Hash -> Blake2b244Hash -> Bool) -> Eq Blake2b244Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Blake2b244Hash -> Blake2b244Hash -> Bool
== :: Blake2b244Hash -> Blake2b244Hash -> Bool
$c/= :: Blake2b244Hash -> Blake2b244Hash -> Bool
/= :: Blake2b244Hash -> Blake2b244Hash -> Bool
Eq, Eq Blake2b244Hash
Eq Blake2b244Hash =>
(Blake2b244Hash -> Blake2b244Hash -> Ordering)
-> (Blake2b244Hash -> Blake2b244Hash -> Bool)
-> (Blake2b244Hash -> Blake2b244Hash -> Bool)
-> (Blake2b244Hash -> Blake2b244Hash -> Bool)
-> (Blake2b244Hash -> Blake2b244Hash -> Bool)
-> (Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash)
-> (Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash)
-> Ord Blake2b244Hash
Blake2b244Hash -> Blake2b244Hash -> Bool
Blake2b244Hash -> Blake2b244Hash -> Ordering
Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Blake2b244Hash -> Blake2b244Hash -> Ordering
compare :: Blake2b244Hash -> Blake2b244Hash -> Ordering
$c< :: Blake2b244Hash -> Blake2b244Hash -> Bool
< :: Blake2b244Hash -> Blake2b244Hash -> Bool
$c<= :: Blake2b244Hash -> Blake2b244Hash -> Bool
<= :: Blake2b244Hash -> Blake2b244Hash -> Bool
$c> :: Blake2b244Hash -> Blake2b244Hash -> Bool
> :: Blake2b244Hash -> Blake2b244Hash -> Bool
$c>= :: Blake2b244Hash -> Blake2b244Hash -> Bool
>= :: Blake2b244Hash -> Blake2b244Hash -> Bool
$cmax :: Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash
max :: Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash
$cmin :: Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash
min :: Blake2b244Hash -> Blake2b244Hash -> Blake2b244Hash
Ord) via PlutusTx.BuiltinByteString
deriving stock (Int -> Blake2b244Hash -> ShowS
[Blake2b244Hash] -> ShowS
Blake2b244Hash -> String
(Int -> Blake2b244Hash -> ShowS)
-> (Blake2b244Hash -> String)
-> ([Blake2b244Hash] -> ShowS)
-> Show Blake2b244Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Blake2b244Hash -> ShowS
showsPrec :: Int -> Blake2b244Hash -> ShowS
$cshow :: Blake2b244Hash -> String
show :: Blake2b244Hash -> String
$cshowList :: [Blake2b244Hash] -> ShowS
showList :: [Blake2b244Hash] -> ShowS
Show)
instance Arbitrary Blake2b244Hash where
{-# INLINEABLE arbitrary #-}
arbitrary :: Gen Blake2b244Hash
arbitrary =
BuiltinByteString -> Blake2b244Hash
Blake2b244Hash (BuiltinByteString -> Blake2b244Hash)
-> (SizedByteString 28 -> BuiltinByteString)
-> SizedByteString 28
-> Blake2b244Hash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasToBuiltin a => a -> ToBuiltin a
PlutusTx.toBuiltin @ByteString (ByteString -> BuiltinByteString)
-> (SizedByteString 28 -> ByteString)
-> SizedByteString 28
-> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (n :: Nat). SizedByteString n -> ByteString
unSizedByteString @28 (SizedByteString 28 -> Blake2b244Hash)
-> Gen (SizedByteString 28) -> Gen Blake2b244Hash
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (SizedByteString 28)
forall a. Arbitrary a => Gen a
arbitrary
deriving via PlutusTx.BuiltinByteString instance CoArbitrary Blake2b244Hash
getBlake2b244Hash :: Blake2b244Hash -> PlutusTx.BuiltinByteString
getBlake2b244Hash :: Blake2b244Hash -> BuiltinByteString
getBlake2b244Hash = Blake2b244Hash -> BuiltinByteString
forall a b. Coercible a b => a -> b
coerce
newtype Blake2b256Hash = Blake2b256Hash PlutusTx.BuiltinByteString
deriving (Blake2b256Hash -> Blake2b256Hash -> Bool
(Blake2b256Hash -> Blake2b256Hash -> Bool)
-> (Blake2b256Hash -> Blake2b256Hash -> Bool) -> Eq Blake2b256Hash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Blake2b256Hash -> Blake2b256Hash -> Bool
== :: Blake2b256Hash -> Blake2b256Hash -> Bool
$c/= :: Blake2b256Hash -> Blake2b256Hash -> Bool
/= :: Blake2b256Hash -> Blake2b256Hash -> Bool
Eq, Eq Blake2b256Hash
Eq Blake2b256Hash =>
(Blake2b256Hash -> Blake2b256Hash -> Ordering)
-> (Blake2b256Hash -> Blake2b256Hash -> Bool)
-> (Blake2b256Hash -> Blake2b256Hash -> Bool)
-> (Blake2b256Hash -> Blake2b256Hash -> Bool)
-> (Blake2b256Hash -> Blake2b256Hash -> Bool)
-> (Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash)
-> (Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash)
-> Ord Blake2b256Hash
Blake2b256Hash -> Blake2b256Hash -> Bool
Blake2b256Hash -> Blake2b256Hash -> Ordering
Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Blake2b256Hash -> Blake2b256Hash -> Ordering
compare :: Blake2b256Hash -> Blake2b256Hash -> Ordering
$c< :: Blake2b256Hash -> Blake2b256Hash -> Bool
< :: Blake2b256Hash -> Blake2b256Hash -> Bool
$c<= :: Blake2b256Hash -> Blake2b256Hash -> Bool
<= :: Blake2b256Hash -> Blake2b256Hash -> Bool
$c> :: Blake2b256Hash -> Blake2b256Hash -> Bool
> :: Blake2b256Hash -> Blake2b256Hash -> Bool
$c>= :: Blake2b256Hash -> Blake2b256Hash -> Bool
>= :: Blake2b256Hash -> Blake2b256Hash -> Bool
$cmax :: Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash
max :: Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash
$cmin :: Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash
min :: Blake2b256Hash -> Blake2b256Hash -> Blake2b256Hash
Ord) via PlutusTx.BuiltinByteString
deriving stock (Int -> Blake2b256Hash -> ShowS
[Blake2b256Hash] -> ShowS
Blake2b256Hash -> String
(Int -> Blake2b256Hash -> ShowS)
-> (Blake2b256Hash -> String)
-> ([Blake2b256Hash] -> ShowS)
-> Show Blake2b256Hash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Blake2b256Hash -> ShowS
showsPrec :: Int -> Blake2b256Hash -> ShowS
$cshow :: Blake2b256Hash -> String
show :: Blake2b256Hash -> String
$cshowList :: [Blake2b256Hash] -> ShowS
showList :: [Blake2b256Hash] -> ShowS
Show)
instance Arbitrary Blake2b256Hash where
{-# INLINEABLE arbitrary #-}
arbitrary :: Gen Blake2b256Hash
arbitrary =
BuiltinByteString -> Blake2b256Hash
Blake2b256Hash (BuiltinByteString -> Blake2b256Hash)
-> (SizedByteString 32 -> BuiltinByteString)
-> SizedByteString 32
-> Blake2b256Hash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasToBuiltin a => a -> ToBuiltin a
PlutusTx.toBuiltin @ByteString (ByteString -> BuiltinByteString)
-> (SizedByteString 32 -> ByteString)
-> SizedByteString 32
-> BuiltinByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (n :: Nat). SizedByteString n -> ByteString
unSizedByteString @32 (SizedByteString 32 -> Blake2b256Hash)
-> Gen (SizedByteString 32) -> Gen Blake2b256Hash
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (SizedByteString 32)
forall a. Arbitrary a => Gen a
arbitrary
deriving via PlutusTx.BuiltinByteString instance CoArbitrary Blake2b256Hash
getBlake2b256Hash :: Blake2b256Hash -> PlutusTx.BuiltinByteString
getBlake2b256Hash :: Blake2b256Hash -> BuiltinByteString
getBlake2b256Hash = Blake2b256Hash -> BuiltinByteString
forall a b. Coercible a b => a -> b
coerce
instance Arbitrary PlutusTx.BuiltinData where
{-# INLINEABLE arbitrary #-}
arbitrary :: Gen BuiltinData
arbitrary = (Int -> Gen BuiltinData) -> Gen BuiltinData
forall a. (Int -> Gen a) -> Gen a
sized ((Int -> Gen BuiltinData) -> Gen BuiltinData)
-> (Int -> Gen BuiltinData) -> Gen BuiltinData
forall a b. (a -> b) -> a -> b
$ \Int
size -> Int -> Gen BuiltinData
go Int
size
where
scaleDown :: forall (a :: Type). Gen a -> Gen a
scaleDown :: forall a. Gen a -> Gen a
scaleDown = (Int -> Int) -> Gen a -> Gen a
forall a. (Int -> Int) -> Gen a -> Gen a
scale (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
4)
go :: Int -> Gen PlutusTx.BuiltinData
go :: Int -> Gen BuiltinData
go Int
size
| Int
size Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = [Gen BuiltinData] -> Gen BuiltinData
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Gen BuiltinData
genB, Gen BuiltinData
genI]
| Bool
otherwise = [Gen BuiltinData] -> Gen BuiltinData
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Gen BuiltinData
genB, Gen BuiltinData
genI, Gen BuiltinData
genConstr, Gen BuiltinData
genList, Gen BuiltinData
genMap]
genB :: Gen PlutusTx.BuiltinData
genB :: Gen BuiltinData
genB = BuiltinByteString -> BuiltinData
Builtins.mkB (BuiltinByteString -> BuiltinData)
-> Gen BuiltinByteString -> Gen BuiltinData
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen BuiltinByteString
forall a. Arbitrary a => Gen a
arbitrary
genI :: Gen PlutusTx.BuiltinData
genI :: Gen BuiltinData
genI = Integer -> BuiltinData
Builtins.mkI (Integer -> BuiltinData) -> Gen Integer -> Gen BuiltinData
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Integer
forall a. Arbitrary a => Gen a
arbitrary
genConstr :: Gen PlutusTx.BuiltinData
genConstr :: Gen BuiltinData
genConstr =
Integer -> [BuiltinData] -> BuiltinData
Builtins.mkConstr (Integer -> [BuiltinData] -> BuiltinData)
-> (NonNegative Integer -> Integer)
-> NonNegative Integer
-> [BuiltinData]
-> BuiltinData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonNegative Integer -> Integer
forall a. NonNegative a -> a
getNonNegative
(NonNegative Integer -> [BuiltinData] -> BuiltinData)
-> Gen (NonNegative Integer) -> Gen ([BuiltinData] -> BuiltinData)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (NonNegative Integer)
forall a. Arbitrary a => Gen a
arbitrary
Gen ([BuiltinData] -> BuiltinData)
-> Gen [BuiltinData] -> Gen BuiltinData
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Gen [BuiltinData] -> Gen [BuiltinData]
forall a. Gen a -> Gen a
scaleDown (Gen BuiltinData -> Gen [BuiltinData]
forall a. Gen a -> Gen [a]
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen BuiltinData
forall a. Arbitrary a => Gen a
arbitrary)
genList :: Gen PlutusTx.BuiltinData
genList :: Gen BuiltinData
genList =
[BuiltinData] -> BuiltinData
Builtins.mkList ([BuiltinData] -> BuiltinData)
-> Gen [BuiltinData] -> Gen BuiltinData
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [BuiltinData] -> Gen [BuiltinData]
forall a. Gen a -> Gen a
scaleDown (Gen BuiltinData -> Gen [BuiltinData]
forall a. Gen a -> Gen [a]
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen BuiltinData
forall a. Arbitrary a => Gen a
arbitrary)
genMap :: Gen PlutusTx.BuiltinData
genMap :: Gen BuiltinData
genMap =
[(BuiltinData, BuiltinData)] -> BuiltinData
Builtins.mkMap ([(BuiltinData, BuiltinData)] -> BuiltinData)
-> Gen [(BuiltinData, BuiltinData)] -> Gen BuiltinData
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [(BuiltinData, BuiltinData)]
-> Gen [(BuiltinData, BuiltinData)]
forall a. Gen a -> Gen a
scaleDown (Gen (BuiltinData, BuiltinData) -> Gen [(BuiltinData, BuiltinData)]
forall a. Gen a -> Gen [a]
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary ((,) (BuiltinData -> BuiltinData -> (BuiltinData, BuiltinData))
-> Gen BuiltinData
-> Gen (BuiltinData -> (BuiltinData, BuiltinData))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen BuiltinData
forall a. Arbitrary a => Gen a
arbitrary Gen (BuiltinData -> (BuiltinData, BuiltinData))
-> Gen BuiltinData -> Gen (BuiltinData, BuiltinData)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Gen BuiltinData
forall a. Arbitrary a => Gen a
arbitrary))
{-# INLINEABLE shrink #-}
shrink :: BuiltinData -> [BuiltinData]
shrink BuiltinData
dat =
BuiltinData
-> (Integer -> [BuiltinData] -> [BuiltinData])
-> ([(BuiltinData, BuiltinData)] -> [BuiltinData])
-> ([BuiltinData] -> [BuiltinData])
-> (Integer -> [BuiltinData])
-> (BuiltinByteString -> [BuiltinData])
-> [BuiltinData]
forall r.
BuiltinData
-> (Integer -> [BuiltinData] -> r)
-> ([(BuiltinData, BuiltinData)] -> r)
-> ([BuiltinData] -> r)
-> (Integer -> r)
-> (BuiltinByteString -> r)
-> r
Builtins.matchData
BuiltinData
dat
Integer -> [BuiltinData] -> [BuiltinData]
shrinkConstr
[(BuiltinData, BuiltinData)] -> [BuiltinData]
shrinkMap
[BuiltinData] -> [BuiltinData]
shrinkList
((NonNegative Integer -> BuiltinData)
-> [NonNegative Integer] -> [BuiltinData]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (Integer -> BuiltinData
Builtins.mkI (Integer -> BuiltinData)
-> (NonNegative Integer -> Integer)
-> NonNegative Integer
-> BuiltinData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonNegative Integer -> Integer
forall a. NonNegative a -> a
getNonNegative) ([NonNegative Integer] -> [BuiltinData])
-> (Integer -> [NonNegative Integer]) -> Integer -> [BuiltinData]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonNegative Integer -> [NonNegative Integer]
forall a. Arbitrary a => a -> [a]
shrink (NonNegative Integer -> [NonNegative Integer])
-> (Integer -> NonNegative Integer)
-> Integer
-> [NonNegative Integer]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NonNegative Integer
forall a. a -> NonNegative a
NonNegative)
((BuiltinByteString -> BuiltinData)
-> [BuiltinByteString] -> [BuiltinData]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap BuiltinByteString -> BuiltinData
Builtins.mkB ([BuiltinByteString] -> [BuiltinData])
-> (BuiltinByteString -> [BuiltinByteString])
-> BuiltinByteString
-> [BuiltinData]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinByteString -> [BuiltinByteString]
forall a. Arbitrary a => a -> [a]
shrink)
where
shrinkConstr :: Integer -> [PlutusTx.BuiltinData] -> [PlutusTx.BuiltinData]
shrinkConstr :: Integer -> [BuiltinData] -> [BuiltinData]
shrinkConstr Integer
ix [BuiltinData]
dats = do
NonNegative Integer
ix' <- NonNegative Integer -> [NonNegative Integer]
forall a. Arbitrary a => a -> [a]
shrink (Integer -> NonNegative Integer
forall a. a -> NonNegative a
NonNegative Integer
ix)
[BuiltinData]
dats' <- [BuiltinData] -> [[BuiltinData]]
forall a. Arbitrary a => a -> [a]
shrink [BuiltinData]
dats
BuiltinData -> [BuiltinData]
forall a. a -> [a]
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (BuiltinData -> [BuiltinData])
-> ([BuiltinData] -> BuiltinData) -> [BuiltinData] -> [BuiltinData]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> [BuiltinData] -> BuiltinData
Builtins.mkConstr Integer
ix' ([BuiltinData] -> [BuiltinData]) -> [BuiltinData] -> [BuiltinData]
forall a b. (a -> b) -> a -> b
$ [BuiltinData]
dats'
shrinkMap :: [(PlutusTx.BuiltinData, PlutusTx.BuiltinData)] -> [PlutusTx.BuiltinData]
shrinkMap :: [(BuiltinData, BuiltinData)] -> [BuiltinData]
shrinkMap [(BuiltinData, BuiltinData)]
kvs = [(BuiltinData, BuiltinData)] -> BuiltinData
Builtins.mkMap ([(BuiltinData, BuiltinData)] -> BuiltinData)
-> [[(BuiltinData, BuiltinData)]] -> [BuiltinData]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> [(BuiltinData, BuiltinData)] -> [[(BuiltinData, BuiltinData)]]
forall a. Arbitrary a => a -> [a]
shrink [(BuiltinData, BuiltinData)]
kvs
shrinkList :: [PlutusTx.BuiltinData] -> [PlutusTx.BuiltinData]
shrinkList :: [BuiltinData] -> [BuiltinData]
shrinkList [BuiltinData]
ell = [BuiltinData] -> BuiltinData
Builtins.mkList ([BuiltinData] -> BuiltinData) -> [[BuiltinData]] -> [BuiltinData]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> [BuiltinData] -> [[BuiltinData]]
forall a. Arbitrary a => a -> [a]
shrink [BuiltinData]
ell
instance CoArbitrary PlutusTx.BuiltinData where
{-# INLINEABLE coarbitrary #-}
coarbitrary :: forall b. BuiltinData -> Gen b -> Gen b
coarbitrary BuiltinData
dat =
BuiltinData
-> (Integer -> [BuiltinData] -> Gen b -> Gen b)
-> ([(BuiltinData, BuiltinData)] -> Gen b -> Gen b)
-> ([BuiltinData] -> Gen b -> Gen b)
-> (Integer -> Gen b -> Gen b)
-> (BuiltinByteString -> Gen b -> Gen b)
-> Gen b
-> Gen b
forall r.
BuiltinData
-> (Integer -> [BuiltinData] -> r)
-> ([(BuiltinData, BuiltinData)] -> r)
-> ([BuiltinData] -> r)
-> (Integer -> r)
-> (BuiltinByteString -> r)
-> r
Builtins.matchData
BuiltinData
dat
(\Integer
ix [BuiltinData]
dats -> Int -> Gen b -> Gen b
forall n a. Integral n => n -> Gen a -> Gen a
variant (Int
0 :: Int) (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Gen b -> Gen b
forall b. Integer -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Integer
ix (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [BuiltinData] -> Gen b -> Gen b
forall b. [BuiltinData] -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary [BuiltinData]
dats)
(\[(BuiltinData, BuiltinData)]
kvs -> Int -> Gen b -> Gen b
forall n a. Integral n => n -> Gen a -> Gen a
variant (Int
1 :: Int) (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(BuiltinData, BuiltinData)] -> Gen b -> Gen b
forall b. [(BuiltinData, BuiltinData)] -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary [(BuiltinData, BuiltinData)]
kvs)
(\[BuiltinData]
ell -> Int -> Gen b -> Gen b
forall n a. Integral n => n -> Gen a -> Gen a
variant (Int
2 :: Int) (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [BuiltinData] -> Gen b -> Gen b
forall b. [BuiltinData] -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary [BuiltinData]
ell)
(\Integer
i -> Int -> Gen b -> Gen b
forall n a. Integral n => n -> Gen a -> Gen a
variant (Int
3 :: Int) (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Gen b -> Gen b
forall b. Integer -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Integer
i)
(\BuiltinByteString
bs -> Int -> Gen b -> Gen b
forall n a. Integral n => n -> Gen a -> Gen a
variant (Int
4 :: Int) (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinByteString -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
forall b. BuiltinByteString -> Gen b -> Gen b
coarbitrary BuiltinByteString
bs)
instance Function PlutusTx.BuiltinData where
{-# INLINEABLE function #-}
function :: forall b. (BuiltinData -> b) -> BuiltinData :-> b
function = (BuiltinData
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> (Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> BuiltinData)
-> (BuiltinData -> b)
-> BuiltinData :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap BuiltinData
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
into Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> BuiltinData
outOf
where
into ::
PlutusTx.BuiltinData ->
Either
(Integer, [PlutusTx.BuiltinData])
( Either
[(PlutusTx.BuiltinData, PlutusTx.BuiltinData)]
( Either
[PlutusTx.BuiltinData]
( Either Integer PlutusTx.BuiltinByteString
)
)
)
into :: BuiltinData
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
into BuiltinData
dat =
BuiltinData
-> (Integer
-> [BuiltinData]
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> ([(BuiltinData, BuiltinData)]
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> ([BuiltinData]
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> (Integer
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> (BuiltinByteString
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall r.
BuiltinData
-> (Integer -> [BuiltinData] -> r)
-> ([(BuiltinData, BuiltinData)] -> r)
-> ([BuiltinData] -> r)
-> (Integer -> r)
-> (BuiltinByteString -> r)
-> r
Builtins.matchData
BuiltinData
dat
(\Integer
ix -> (Integer, [BuiltinData])
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall a b. a -> Either a b
Left ((Integer, [BuiltinData])
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> ([BuiltinData] -> (Integer, [BuiltinData]))
-> [BuiltinData]
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer
ix,))
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall a b. b -> Either a b
Right (Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> ([(BuiltinData, BuiltinData)]
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> [(BuiltinData, BuiltinData)]
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(BuiltinData, BuiltinData)]
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall a b. a -> Either a b
Left)
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall a b. b -> Either a b
Right (Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> ([BuiltinData]
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> [BuiltinData]
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either [BuiltinData] (Either Integer BuiltinByteString)
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall a b. b -> Either a b
Right (Either [BuiltinData] (Either Integer BuiltinByteString)
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> ([BuiltinData]
-> Either [BuiltinData] (Either Integer BuiltinByteString))
-> [BuiltinData]
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [BuiltinData]
-> Either [BuiltinData] (Either Integer BuiltinByteString)
forall a b. a -> Either a b
Left)
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall a b. b -> Either a b
Right (Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> (Integer
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> Integer
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either [BuiltinData] (Either Integer BuiltinByteString)
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall a b. b -> Either a b
Right (Either [BuiltinData] (Either Integer BuiltinByteString)
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> (Integer
-> Either [BuiltinData] (Either Integer BuiltinByteString))
-> Integer
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Integer BuiltinByteString
-> Either [BuiltinData] (Either Integer BuiltinByteString)
forall a b. b -> Either a b
Right (Either Integer BuiltinByteString
-> Either [BuiltinData] (Either Integer BuiltinByteString))
-> (Integer -> Either Integer BuiltinByteString)
-> Integer
-> Either [BuiltinData] (Either Integer BuiltinByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Either Integer BuiltinByteString
forall a b. a -> Either a b
Left)
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall a b. b -> Either a b
Right (Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))))
-> (BuiltinByteString
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> BuiltinByteString
-> Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either [BuiltinData] (Either Integer BuiltinByteString)
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall a b. b -> Either a b
Right (Either [BuiltinData] (Either Integer BuiltinByteString)
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> (BuiltinByteString
-> Either [BuiltinData] (Either Integer BuiltinByteString))
-> BuiltinByteString
-> Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either Integer BuiltinByteString
-> Either [BuiltinData] (Either Integer BuiltinByteString)
forall a b. b -> Either a b
Right (Either Integer BuiltinByteString
-> Either [BuiltinData] (Either Integer BuiltinByteString))
-> (BuiltinByteString -> Either Integer BuiltinByteString)
-> BuiltinByteString
-> Either [BuiltinData] (Either Integer BuiltinByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BuiltinByteString -> Either Integer BuiltinByteString
forall a b. b -> Either a b
Right)
outOf ::
Either
(Integer, [PlutusTx.BuiltinData])
( Either
[(PlutusTx.BuiltinData, PlutusTx.BuiltinData)]
( Either
[PlutusTx.BuiltinData]
( Either Integer PlutusTx.BuiltinByteString
)
)
) ->
PlutusTx.BuiltinData
outOf :: Either
(Integer, [BuiltinData])
(Either
[(BuiltinData, BuiltinData)]
(Either [BuiltinData] (Either Integer BuiltinByteString)))
-> BuiltinData
outOf = \case
Left (Integer
ix, [BuiltinData]
dats) -> Integer -> [BuiltinData] -> BuiltinData
Builtins.mkConstr Integer
ix [BuiltinData]
dats
Right (Left [(BuiltinData, BuiltinData)]
kvs) -> [(BuiltinData, BuiltinData)] -> BuiltinData
Builtins.mkMap [(BuiltinData, BuiltinData)]
kvs
Right (Right (Left [BuiltinData]
ell)) -> [BuiltinData] -> BuiltinData
Builtins.mkList [BuiltinData]
ell
Right (Right (Right (Left Integer
i))) -> Integer -> BuiltinData
Builtins.mkI Integer
i
Right (Right (Right (Right BuiltinByteString
bs))) -> BuiltinByteString -> BuiltinData
Builtins.mkB BuiltinByteString
bs
instance (Arbitrary k, Ord k) => Arbitrary1 (AssocMap.Map k) where
{-# INLINEABLE liftArbitrary #-}
liftArbitrary :: forall a. Gen a -> Gen (Map k a)
liftArbitrary Gen a
genVal =
[(k, a)] -> Map k a
forall k v. [(k, v)] -> Map k v
AssocMap.unsafeFromList ([(k, a)] -> Map k a) -> Gen [(k, a)] -> Gen (Map k a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> do
[k]
keyList <- Set k -> [k]
forall a. Set a -> [a]
Set.toList (Set k -> [k]) -> Gen (Set k) -> Gen [k]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Set k)
forall a. Arbitrary a => Gen a
arbitrary
(k -> Gen (k, a)) -> [k] -> Gen [(k, a)]
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (\k
key -> (k
key,) (a -> (k, a)) -> Gen a -> Gen (k, a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
genVal) [k]
keyList
{-# INLINEABLE liftShrink #-}
liftShrink :: forall a. (a -> [a]) -> Map k a -> [Map k a]
liftShrink a -> [a]
shrinkVal Map k a
aMap =
[(k, a)] -> Map k a
forall k v. [(k, v)] -> Map k v
AssocMap.unsafeFromList ([(k, a)] -> Map k a) -> [[(k, a)]] -> [Map k a]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> do
let asList :: [(k, a)]
asList = Map k a -> [(k, a)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList Map k a
aMap
((k, a) -> [(k, a)]) -> [(k, a)] -> [[(k, a)]]
forall a. (a -> [a]) -> [a] -> [[a]]
forall (f :: Type -> Type) a.
Arbitrary1 f =>
(a -> [a]) -> f a -> [f a]
liftShrink (\(k
key, a
val) -> (k
key,) (a -> (k, a)) -> [a] -> [(k, a)]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> [a]
shrinkVal a
val) [(k, a)]
asList
instance (Arbitrary k, Arbitrary v, Ord k) => Arbitrary (AssocMap.Map k v) where
{-# INLINEABLE arbitrary #-}
arbitrary :: Gen (Map k v)
arbitrary = Gen v -> Gen (Map k v)
forall a. Gen a -> Gen (Map k a)
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen v
forall a. Arbitrary a => Gen a
arbitrary
{-# INLINEABLE shrink #-}
shrink :: Map k v -> [Map k v]
shrink = (v -> [v]) -> Map k v -> [Map k v]
forall a. (a -> [a]) -> Map k a -> [Map k a]
forall (f :: Type -> Type) a.
Arbitrary1 f =>
(a -> [a]) -> f a -> [f a]
liftShrink v -> [v]
forall a. Arbitrary a => a -> [a]
shrink
instance (CoArbitrary k, CoArbitrary v) => CoArbitrary (AssocMap.Map k v) where
{-# INLINEABLE coarbitrary #-}
coarbitrary :: forall b. Map k v -> Gen b -> Gen b
coarbitrary = [(k, v)] -> Gen b -> Gen b
forall b. [(k, v)] -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary ([(k, v)] -> Gen b -> Gen b)
-> (Map k v -> [(k, v)]) -> Map k v -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k v -> [(k, v)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList
instance (Function k, Function v) => Function (AssocMap.Map k v) where
{-# INLINEABLE function #-}
function :: forall b. (Map k v -> b) -> Map k v :-> b
function = (Map k v -> [(k, v)])
-> ([(k, v)] -> Map k v) -> (Map k v -> b) -> Map k v :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Map k v -> [(k, v)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList [(k, v)] -> Map k v
forall k v. [(k, v)] -> Map k v
AssocMap.unsafeFromList
newtype UnsortedAssocMap k v = UnsortedAssocMap (AssocMap.Map k v)
deriving newtype (Int -> UnsortedAssocMap k v -> ShowS
[UnsortedAssocMap k v] -> ShowS
UnsortedAssocMap k v -> String
(Int -> UnsortedAssocMap k v -> ShowS)
-> (UnsortedAssocMap k v -> String)
-> ([UnsortedAssocMap k v] -> ShowS)
-> Show (UnsortedAssocMap k v)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k v.
(Show k, Show v) =>
Int -> UnsortedAssocMap k v -> ShowS
forall k v. (Show k, Show v) => [UnsortedAssocMap k v] -> ShowS
forall k v. (Show k, Show v) => UnsortedAssocMap k v -> String
$cshowsPrec :: forall k v.
(Show k, Show v) =>
Int -> UnsortedAssocMap k v -> ShowS
showsPrec :: Int -> UnsortedAssocMap k v -> ShowS
$cshow :: forall k v. (Show k, Show v) => UnsortedAssocMap k v -> String
show :: UnsortedAssocMap k v -> String
$cshowList :: forall k v. (Show k, Show v) => [UnsortedAssocMap k v] -> ShowS
showList :: [UnsortedAssocMap k v] -> ShowS
Show, UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
(UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool)
-> (UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool)
-> Eq (UnsortedAssocMap k v)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k v.
(Ord k, Eq v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
$c== :: forall k v.
(Ord k, Eq v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
== :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
$c/= :: forall k v.
(Ord k, Eq v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
/= :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
Eq, Eq (UnsortedAssocMap k v)
Eq (UnsortedAssocMap k v) =>
(UnsortedAssocMap k v -> UnsortedAssocMap k v -> Ordering)
-> (UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool)
-> (UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool)
-> (UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool)
-> (UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool)
-> (UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v)
-> (UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v)
-> Ord (UnsortedAssocMap k v)
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Ordering
UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k v. (Ord k, Ord v) => Eq (UnsortedAssocMap k v)
forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Ordering
forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v
$ccompare :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Ordering
compare :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Ordering
$c< :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
< :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
$c<= :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
<= :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
$c> :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
> :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
$c>= :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
>= :: UnsortedAssocMap k v -> UnsortedAssocMap k v -> Bool
$cmax :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v
max :: UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v
$cmin :: forall k v.
(Ord k, Ord v) =>
UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v
min :: UnsortedAssocMap k v
-> UnsortedAssocMap k v -> UnsortedAssocMap k v
Ord, (forall ann. UnsortedAssocMap k v -> Doc ann)
-> (forall ann. [UnsortedAssocMap k v] -> Doc ann)
-> Pretty (UnsortedAssocMap k v)
forall ann. [UnsortedAssocMap k v] -> Doc ann
forall ann. UnsortedAssocMap k v -> Doc ann
forall a.
(forall ann. a -> Doc ann)
-> (forall ann. [a] -> Doc ann) -> Pretty a
forall k v ann.
(Pretty k, Pretty v) =>
[UnsortedAssocMap k v] -> Doc ann
forall k v ann.
(Pretty k, Pretty v) =>
UnsortedAssocMap k v -> Doc ann
$cpretty :: forall k v ann.
(Pretty k, Pretty v) =>
UnsortedAssocMap k v -> Doc ann
pretty :: forall ann. UnsortedAssocMap k v -> Doc ann
$cprettyList :: forall k v ann.
(Pretty k, Pretty v) =>
[UnsortedAssocMap k v] -> Doc ann
prettyList :: forall ann. [UnsortedAssocMap k v] -> Doc ann
Pretty)
instance (Arbitrary k, Ord k) => Arbitrary1 (UnsortedAssocMap k) where
{-# INLINEABLE liftArbitrary #-}
liftArbitrary :: forall a. Gen a -> Gen (UnsortedAssocMap k a)
liftArbitrary Gen a
genVal =
Map k a -> UnsortedAssocMap k a
forall k v. Map k v -> UnsortedAssocMap k v
UnsortedAssocMap (Map k a -> UnsortedAssocMap k a)
-> ([(k, a)] -> Map k a) -> [(k, a)] -> UnsortedAssocMap k a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(k, a)] -> Map k a
forall k v. [(k, v)] -> Map k v
AssocMap.unsafeFromList ([(k, a)] -> UnsortedAssocMap k a)
-> Gen [(k, a)] -> Gen (UnsortedAssocMap k a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> do
[k]
keyList <- Set k -> [k]
forall a. Set a -> [a]
Set.toList (Set k -> [k]) -> Gen (Set k) -> Gen [k]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Set k)
forall a. Arbitrary a => Gen a
arbitrary
[k]
unsortedKeyList <- [k] -> Gen [k]
forall a. [a] -> Gen [a]
shuffle [k]
keyList
(k -> Gen (k, a)) -> [k] -> Gen [(k, a)]
forall (t :: Type -> Type) (f :: Type -> Type) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (\k
key -> (k
key,) (a -> (k, a)) -> Gen a -> Gen (k, a)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen a
genVal) [k]
unsortedKeyList
{-# INLINEABLE liftShrink #-}
liftShrink :: forall a.
(a -> [a]) -> UnsortedAssocMap k a -> [UnsortedAssocMap k a]
liftShrink a -> [a]
shrinkVal (UnsortedAssocMap Map k a
aMap) =
Map k a -> UnsortedAssocMap k a
forall k v. Map k v -> UnsortedAssocMap k v
UnsortedAssocMap (Map k a -> UnsortedAssocMap k a)
-> ([(k, a)] -> Map k a) -> [(k, a)] -> UnsortedAssocMap k a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(k, a)] -> Map k a
forall k v. [(k, v)] -> Map k v
AssocMap.unsafeFromList ([(k, a)] -> UnsortedAssocMap k a)
-> [[(k, a)]] -> [UnsortedAssocMap k a]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> do
let asList :: [(k, a)]
asList = Map k a -> [(k, a)]
forall k v. Map k v -> [(k, v)]
AssocMap.toList Map k a
aMap
((k, a) -> [(k, a)]) -> [(k, a)] -> [[(k, a)]]
forall a. (a -> [a]) -> [a] -> [[a]]
forall (f :: Type -> Type) a.
Arbitrary1 f =>
(a -> [a]) -> f a -> [f a]
liftShrink (\(k
key, a
val) -> (k
key,) (a -> (k, a)) -> [a] -> [(k, a)]
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> [a]
shrinkVal a
val) [(k, a)]
asList
instance (Arbitrary k, Arbitrary v, Ord k) => Arbitrary (UnsortedAssocMap k v) where
{-# INLINEABLE arbitrary #-}
arbitrary :: Gen (UnsortedAssocMap k v)
arbitrary = Gen v -> Gen (UnsortedAssocMap k v)
forall a. Gen a -> Gen (UnsortedAssocMap k a)
forall (f :: Type -> Type) a. Arbitrary1 f => Gen a -> Gen (f a)
liftArbitrary Gen v
forall a. Arbitrary a => Gen a
arbitrary
{-# INLINEABLE shrink #-}
shrink :: UnsortedAssocMap k v -> [UnsortedAssocMap k v]
shrink = (v -> [v]) -> UnsortedAssocMap k v -> [UnsortedAssocMap k v]
forall a.
(a -> [a]) -> UnsortedAssocMap k a -> [UnsortedAssocMap k a]
forall (f :: Type -> Type) a.
Arbitrary1 f =>
(a -> [a]) -> f a -> [f a]
liftShrink v -> [v]
forall a. Arbitrary a => a -> [a]
shrink
instance (CoArbitrary k, CoArbitrary v) => CoArbitrary (UnsortedAssocMap k v) where
{-# INLINEABLE coarbitrary #-}
coarbitrary :: forall b. UnsortedAssocMap k v -> Gen b -> Gen b
coarbitrary (UnsortedAssocMap Map k v
aMap) = Map k v -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
forall b. Map k v -> Gen b -> Gen b
coarbitrary Map k v
aMap
instance (Function k, Function v) => Function (UnsortedAssocMap k v) where
{-# INLINEABLE function #-}
function :: forall b. (UnsortedAssocMap k v -> b) -> UnsortedAssocMap k v :-> b
function = forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap @(AssocMap.Map k v) UnsortedAssocMap k v -> Map k v
forall a b. Coercible a b => a -> b
coerce Map k v -> UnsortedAssocMap k v
forall a b. Coercible a b => a -> b
coerce
getUnsortedAssocMap :: UnsortedAssocMap k v -> AssocMap.Map k v
getUnsortedAssocMap :: forall k v. UnsortedAssocMap k v -> Map k v
getUnsortedAssocMap = UnsortedAssocMap k v -> Map k v
forall a b. Coercible a b => a -> b
coerce