{-# OPTIONS_GHC -Wno-orphans #-}

module Test.Cardano.StrictContainers.Instances where

import Test.QuickCheck (Arbitrary (..))

import Data.Foldable (toList)
import Data.Maybe.Strict
import Data.Sequence.Strict (StrictSeq (..))
import qualified Data.Sequence.Strict as SSeq

instance Arbitrary e => Arbitrary (StrictSeq e) where
  arbitrary :: Gen (StrictSeq e)
arbitrary = [e] -> StrictSeq e
forall a. [a] -> StrictSeq a
SSeq.fromList ([e] -> StrictSeq e) -> Gen [e] -> Gen (StrictSeq e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen [e]
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: StrictSeq e -> [StrictSeq e]
shrink = ([e] -> StrictSeq e) -> [[e]] -> [StrictSeq e]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [e] -> StrictSeq e
forall a. [a] -> StrictSeq a
SSeq.fromList ([[e]] -> [StrictSeq e])
-> (StrictSeq e -> [[e]]) -> StrictSeq e -> [StrictSeq e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [e] -> [[e]]
forall a. Arbitrary a => a -> [a]
shrink ([e] -> [[e]]) -> (StrictSeq e -> [e]) -> StrictSeq e -> [[e]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictSeq e -> [e]
forall a. StrictSeq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

instance Arbitrary e => Arbitrary (StrictMaybe e) where
  arbitrary :: Gen (StrictMaybe e)
arbitrary = Maybe e -> StrictMaybe e
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe (Maybe e -> StrictMaybe e) -> Gen (Maybe e) -> Gen (StrictMaybe e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Maybe e)
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: StrictMaybe e -> [StrictMaybe e]
shrink = (Maybe e -> StrictMaybe e) -> [Maybe e] -> [StrictMaybe e]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe e -> StrictMaybe e
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe ([Maybe e] -> [StrictMaybe e])
-> (StrictMaybe e -> [Maybe e]) -> StrictMaybe e -> [StrictMaybe e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe e -> [Maybe e]
forall a. Arbitrary a => a -> [a]
shrink (Maybe e -> [Maybe e])
-> (StrictMaybe e -> Maybe e) -> StrictMaybe e -> [Maybe e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictMaybe e -> Maybe e
forall a. StrictMaybe a -> Maybe a
strictMaybeToMaybe