SafeGen

@dynamicMemberLookup
public struct SafeGen<T>

Combines Gen member lookup with the “safe” extensions

  • The base Gen instance which has been enhanced by safe functionality

    Declaration

    Swift

    public let base: Gen<T>
  • Creates extensions with base object.

    Declaration

    Swift

    public init(_ base: Gen<T>)

    Parameters

    base

    Base object.

Generation

  • 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

Produce

  • 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 value

    Declaration

    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 value

    context

    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 value

    Declaration

    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 value

    context

    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 value

    context

    The context to be used for generation

    Return Value

    An array of generated values