Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implements fictional's someOf primitive #33

Merged
merged 1 commit into from Oct 17, 2022

Conversation

dthyresson
Copy link
Contributor

This PR implement's fictional's someOf which:

Takes in an identifying input value and an array of values, repeatedly picks items from that array a number of times within the given range. Each item will be picked no more than once.

someOf('id-23', [1, 2], ['red', 'green', 'blue'])
// =>
[
  'green'
]

This is useful when seeding string arrays seen here as tags in Prisma models like:

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String
  tags      String[]
}

While the following oneOf can be performed:

copycat.oneOf([tech, life, music, art, science]),

There was no way in copycat to make an array like ['tech', 'art'].

The someOf function now lets you generate deterministic collections.

@justinvdm
Copy link
Contributor

Thank you for the PR @dthyresson! From your example, I can see how someOf() fits into copycat's API for the use cases we've been keeping in mind.

@justinvdm justinvdm merged commit b19a4c8 into snaplet:main Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants