Skip to content

[FEATURE] Add generic method equivalent of RandomElement... and RandomMap... #230

Description

@mathieu-lemay

With Go 1.27's new generic methods, it would be possible to add a method variant of those four functions, which I think is much nicer to use.

Example:

var fake = faker.New()

// Instead of
v1 := faker.RandomElement(fake, 1, 2, 3, 4, 5)

// We could do this, much more natural in my opinion
v2 := fake.RandomElement(1, 2, 3, 4, 5)

This can be done while keeping compatibility with Go 1.22, by using conditional build tags.

If this something that you would be interested in? If so, I'd be more than happy to open a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions