Closed effect-bot closed 1 week ago
See The playground for a demonstration.
jessekelly881/effect-schema-compilers/blob/main/src/faker.ts has incorporated an option for this for fakerjs, which might be a nice way to handle it here. Alternatively, passing the Artibrary.ts/go
function and current arguments to the arbitrary
handler might work as well, and provide more flexibility.
(As an aside, but probably a different issue, built-in integration with faker might be nice. I currently use this for some arbitraries:
import { faker, Faker } from '@faker-js/faker'
import { FastCheck } from '@effect/schema'
export const fakerToArb = <A>(fakerGen: (faker: Faker) => A) =>
() => (fc: typeof FastCheck) => {
return fc
.noShrink(
// shrink on a seed makes no sense
fc.noBias(
// same probability to generate each of the allowed integers
fc.integer(),
),
)
.map((seed) => {
faker.seed(seed); // seed the generator
return fakerGen(faker); // call it
});
};
See The playground for a demonstration
@nspaeth It's me or ^ this just shows the default code?
Not sure what happened. I fixed the link!
@gcanti I've updated the playground to include a case with recursive Maps:
@nspaeth I get an "Application error" now, better to paste the repros here I guess
All of my links seem to have stopped working. There seems to be some bug in the playground, as I double checked them all when updating them after you initially couldn't access them.
I don't have a local copy of the repro.
There seems to be some bug in the playground
This should now be fixed. Apologies for the inconvenience!
@nspaeth PR here https://github.com/Effect-TS/effect/pull/3560
(you can try it out by running pnpm add https://pkg.pr.new/Effect-TS/effect/@effect/schema@f7008f7
)
Summary
Summary
spaethnl
asked about limiting the amount of nesting or the total number of schemas instantiated when generating arbitraries, particularly for a recursive schema to prevent infinite schemas.datner_
clarified that arbitraries don't generate schemas and suggested checking thefast-check
documentation.spaethnl
elaborated on trying to passdepthFactor
anddepthSize
into a schema's arbitrary interface or applyingcreateDepthIdentifier
to a schema. They also considered using a custom arbitrary handler.datner_
admitted to not understanding the technical details but encouraged posting any improvement suggestions to their repository.timsmart
suggested using thefc.letrec
API to create recursive structures and referenced thecauseArbitrary
in the effect schema source.spaethnl
shared a link to a demonstration of the issue and mentioned the challenge of incorporatingfc.letrec
into a more complex schema without copying thego
function fromArbitrary
.Key Takeaways
fc.letrec
API can be useful for creating recursive structures.Discord thread
https://discord.com/channels/795981131316985866/1278090821287284746