SafeGen
@dynamicMemberLookup
public struct SafeGen<T>
Combines Gen member lookup with the “safe” extensions
-
Returns: A single value produced by the generator using the provided Context
Declaration
Swift
func generate(context: Context = .default) throws -> T
Parameters
context
The context to be used for generation
Return Value
A value of type
T
-
Returns: A Boolean value indicating whether every element of a sequence satisfies a given predicate
Will run n times, where n is the provided
iterations
or the context’s valueDeclaration
Swift
func allSatisfy(iterations: Int? = nil, context: Context = .default, _ predicate: (T) throws -> Bool) throws -> Bool
Parameters
iterations
The amount of times the sequence should iterate, default’s to the context’s
maxIterations
valuecontext
The context to be used for generation
predicate
A closure that takes an element of the sequence as its argument and returns a Boolean value that indicates whether the passed element satisfies a condition.
Return Value
The Boolean result
-
Iterates (lazily) over a sequence and executes a given predicate
body
Will run n times, where n is the provided
iterations
or the context’s valueDeclaration
Swift
func forEach(iterations: Int? = nil, context: Context = .default, _ body: (T) throws -> Void) throws
Parameters
iterations
The amount of times the sequence should iterate, default’s to the context’s
maxIterations
valuecontext
The context to be used for generation
-
Returns: Non-deterministic random samples of the generator’s values
Warning
Recommended to be used only to evaluate or demonstrate the generator
Declaration
Swift
func samples(count: Int = 20) throws -> [T]
Parameters
count
The amount of values to be returned as samples
Return Value
An array of sample values
-
Returns: A single non-deterministic random sample of the generator’s values
Warning
Recommended to be used only to evaluate or demonstrate the generator
Declaration
Swift
func sample() throws -> T
Return Value
A sample value
-
Returns: An array of values from the generator
Declaration
Swift
func take(count: Int? = nil, context: Context = .default) throws -> [T]
Parameters
count
The amount of values to generate, default’s to the context’s
iterations
valuecontext
The context to be used for generation
Return Value
An array of generated values