fakedata-0.2.2: Library for producing fake data

Safe HaskellSafe
LanguageHaskell2010

Faker

Contents

Synopsis

Types

newtype Fake a Source #

Fake data type. This is the type you will be using to produce fake values.

Constructors

Fake 

Fields

Instances
Monad Fake Source # 
Instance details

Defined in Faker

Methods

(>>=) :: Fake a -> (a -> Fake b) -> Fake b #

(>>) :: Fake a -> Fake b -> Fake b #

return :: a -> Fake a #

fail :: String -> Fake a #

Functor Fake Source # 
Instance details

Defined in Faker

Methods

fmap :: (a -> b) -> Fake a -> Fake b #

(<$) :: a -> Fake b -> Fake a #

Applicative Fake Source # 
Instance details

Defined in Faker

Methods

pure :: a -> Fake a #

(<*>) :: Fake (a -> b) -> Fake a -> Fake b #

liftA2 :: (a -> b -> c) -> Fake a -> Fake b -> Fake c #

(*>) :: Fake a -> Fake b -> Fake b #

(<*) :: Fake a -> Fake b -> Fake a #

MonadIO Fake Source # 
Instance details

Defined in Faker

Methods

liftIO :: IO a -> Fake a #

data FakerSettings Source #

Instances
Show FakerSettings Source # 
Instance details

Defined in Faker

data FakerException Source #

Constructors

InvalidLocale String

This is thrown when it is not able to find the fake data source for your localization.

InvalidField String Text

The String represents the field is trying to resolve and the Text field is something you passed on.

NoDataFound FakerSettings

This is thrown when you have no data. This may likely happen for locales other than en.

defaultFakerSettings :: FakerSettings Source #

Default faker settings with locale of "en" and Deterministic output.

Setters

setLocale :: Text -> FakerSettings -> FakerSettings Source #

Sets the locale. Note that for any other locale apart from "en", you need to make sure that the data is acutally present. In case no data is found, NoDataFound exception will be thrown. You can check the presence of the data in a particular locale by inspecting the yml file of the corresponding locale. The file would be bundled along with the particular Hackage release.

setRandomGen :: StdGen -> FakerSettings -> FakerSettings Source #

Sets the random generator

setDeterministic :: FakerSettings -> FakerSettings Source #

Set the output of fakedata to be deterministic. With this you will get the same ouput for the functions every time.

λ> import qualified Faker.Name as FN
λ> :t FN.name
FN.name :: Fake Text
λ> generateWithSettings (setDeterministic defaultFakerSettings) FN.name
"Antony Langosh"
λ> generateWithSettings (setDeterministic defaultFakerSettings) FN.name
"Antony Langosh"

setNonDeterministic :: FakerSettings -> FakerSettings Source #

Set the output of fakedata to be non deterministic. With this you will get different ouput for the fake functions.

λ> generateWithSettings (setNonDeterministic defaultFakerSettings) FN.name
"Macy Shanahan"
λ> generateWithSettings (setNonDeterministic defaultFakerSettings) FN.name
"Rudy Dickinson II"

Getters

getRandomGen :: FakerSettings -> StdGen Source #

Get the random generator

getLocale :: FakerSettings -> Text Source #

Get the Locale settings for your fake data source

getDeterministic :: FakerSettings -> Bool Source #

Check if the fake data output is deterministic or not. A True value indicates that it is deterministic.

Generators

generate :: Fake a -> IO a Source #

Generate fake value with defaultFakerSettings

λ> import qualified Faker.Name as FN
λ> generate FN.name
"Antony Langosh"

generateWithSettings :: FakerSettings -> Fake a -> IO a Source #

Generate fake value with supplied FakerSettings

λ> generateWithSettings defaultFakerSettings FN.name
"Antony Langosh"