module Test.LeanCheck.Function.List
( funToList
, funToListMaybe
, funToListEither
, areEqualFor
, compareFor
)
where
import Test.LeanCheck
import Test.LeanCheck.Error (errorToNothing, errorToLeft)
import Data.Function (on)
funToList :: Listable a => (a -> b) -> [b]
funToList :: forall a b. Listable a => (a -> b) -> [b]
funToList a -> b
f = (a -> b) -> [a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map a -> b
f [a]
forall a. Listable a => [a]
list
funToListMaybe :: Listable a => (a -> b) -> [Maybe b]
funToListMaybe :: forall a b. Listable a => (a -> b) -> [Maybe b]
funToListMaybe a -> b
f = (a -> Maybe b) -> [a] -> [Maybe b]
forall a b. (a -> b) -> [a] -> [b]
map (b -> Maybe b
forall a. a -> Maybe a
errorToNothing (b -> Maybe b) -> (a -> b) -> a -> Maybe b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) [a]
forall a. Listable a => [a]
list
funToListEither :: Listable a => (a -> b) -> [Either String b]
funToListEither :: forall a b. Listable a => (a -> b) -> [Either String b]
funToListEither a -> b
f = (a -> Either String b) -> [a] -> [Either String b]
forall a b. (a -> b) -> [a] -> [b]
map (b -> Either String b
forall a. a -> Either String a
errorToLeft (b -> Either String b) -> (a -> b) -> a -> Either String b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f) [a]
forall a. Listable a => [a]
list
areEqualFor :: (Listable a, Eq b) => Int -> (a -> b) -> (a -> b) -> Bool
areEqualFor :: forall a b.
(Listable a, Eq b) =>
Int -> (a -> b) -> (a -> b) -> Bool
areEqualFor Int
n = [Maybe b] -> [Maybe b] -> Bool
forall a. Eq a => a -> a -> Bool
(==) ([Maybe b] -> [Maybe b] -> Bool)
-> ((a -> b) -> [Maybe b]) -> (a -> b) -> (a -> b) -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Int -> [Maybe b] -> [Maybe b]
forall a. Int -> [a] -> [a]
take Int
n ([Maybe b] -> [Maybe b])
-> ((a -> b) -> [Maybe b]) -> (a -> b) -> [Maybe b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> [Maybe b]
forall a b. Listable a => (a -> b) -> [Maybe b]
funToListMaybe)
compareFor :: (Listable a, Ord b) => Int -> (a -> b) -> (a -> b) -> Ordering
compareFor :: forall a b.
(Listable a, Ord b) =>
Int -> (a -> b) -> (a -> b) -> Ordering
compareFor Int
n = [Maybe b] -> [Maybe b] -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ([Maybe b] -> [Maybe b] -> Ordering)
-> ((a -> b) -> [Maybe b]) -> (a -> b) -> (a -> b) -> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` (Int -> [Maybe b] -> [Maybe b]
forall a. Int -> [a] -> [a]
take Int
n ([Maybe b] -> [Maybe b])
-> ((a -> b) -> [Maybe b]) -> (a -> b) -> [Maybe b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> [Maybe b]
forall a b. Listable a => (a -> b) -> [Maybe b]
funToListMaybe)