fakedata-0.8.0: Library for producing fake data

Safe HaskellNone
LanguageHaskell2010

Faker.Combinators

Synopsis

Documentation

fromRange :: Random a => (a, a) -> Fake a Source #

Generates a random element in the given inclusive range.

λ> item <- generate $ fromRange (1,10)
λ> item
2

pickAny :: Random a => Fake a Source #

Generates a random element over the natural range of a.

λ> import Data.Word
λ> item :: Word8 <- generate pickAny
λ> item
57

suchThatMaybe :: Fake a -> (a -> Bool) -> Fake (Maybe a) Source #

Tries to generate a value that satisfies a predicate.

λ> import qualified Faker.Address as AD
λ> item :: Text <- generate $ suchThatMaybe AD.country (x -> (T.length x > 5))
λ> item
Just Ecuador

suchThat :: Fake a -> (a -> Bool) -> Fake a Source #

Generates a value that satisfies a predicate.

λ> import qualified Faker.Address as AD
λ> item :: Text <- generate $ suchThat AD.country (\x -> (T.length x > 5))
λ> item
Ecuador

oneof :: Foldable t => t (Fake a) -> Fake a Source #

Randomly uses one of the given generators. The input structure must be non-empty.

λ> import qualified Faker.Address as FA
λ> let fakes = [FA.country, FA.postcode, FA.state]
λ> generate (oneof fakes)
Montana

elements :: Foldable t => t a -> Fake a Source #

Generates one of the given values. The input list must be non-empty.

λ> let fakeInt = elements [1..100]
λ> generate fakeInt
22

listOf :: Int -> Fake a -> Fake [a] Source #

Generates a list of the given length.

orderedList :: Ord a => Int -> Fake a -> Fake [a] Source #

Generates an ordered list.

frequency :: [(Int, Fake a)] -> Fake a Source #

Chooses one of the given generators, with a weighted random distribution. The input list must be non-empty.

fakeEnumFromTo :: Enum a => a -> a -> Fake a Source #

Generate a value of an enumeration in the range [from, to].

λ> data Animal = Cat | Dog | Zebra | Elephant | Giarfee deriving (Eq,Ord,Enum, Show)
λ> generate (fakeEnumFromTo Cat Zebra)
Zebra

Since: 0.2.0

fakeBoundedEnum :: (Enum a, Bounded a) => Fake a Source #

A sumtype can just use this function directly. Defined as fakeBoundedEnum = fakeEnumFromTo minBound maxBound

Since: 0.7.1