Effect CommunityEC
Effect Community2y ago
6 replies
mkrause

Unexpected output from `Schema.encodedSchema` with FastCheck

import { Arbitrary, FastCheck, Schema } from "@effect/schema";

FastCheck.sample(Arbitrary.make(Schema.UUID), 1);
// 'b85330cc-001b-1000-bfff-fff500000001'

FastCheck.sample(Arbitrary.make(Schema.encodedSchema(Schema.UUID)), 1);
// '")s"G/'


This is interesting. I would have expected the second call with Schema.encodedSchema to return a valid UUID string. Although technically the random string is a valid instance of the type I (namely string), it would not actually decode if you ran it through S.decode(Schema.UUID).

I was trying to use this to generate sample data that could be decoded successfully, but as far as I can see that's not possible. Unless I sample the A data instead (first line of code) and then encode that.
Was this page helpful?