Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Is there a way to make generated data optional? #161

@lexuzieel

Description

@lexuzieel

Sometimes it is useful to generate randomly optional fields, such as the last name (but really - almost any field).

Is it possible to do something like this:

firstName := faker.FirstName()
lastName := faker.Optional(.5).LastName() // <-- Generate non-empty last name 50% of the time

fullName := firstName
if lastName != "" {
    fullName += " " + lastName
}

println("Hello, " + fullName + "!")

Here faker.LastName() would return empty string 50% of the time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions