github Effect-TS/effect effect@3.13.6

latest releases: @effect/vitest@0.19.4, @effect/typeclass@0.32.6, @effect/sql-sqlite-wasm@0.31.6...
20 hours ago

Patch Changes

  • #4551 3154ce4 Thanks @gcanti! - Arbitrary: make called on Schema.Class now respects property annotations, closes #4550.

    Previously, when calling Arbitrary.make on a Schema.Class, property-specific annotations (such as arbitrary) were ignored, leading to unexpected values in generated instances.

    Before

    Even though a had an arbitrary annotation, the generated values were random:

    import { Arbitrary, FastCheck, Schema } from "effect"
    
    class Class extends Schema.Class<Class>("Class")({
      a: Schema.NumberFromString.annotations({
        arbitrary: () => (fc) => fc.constant(1)
      })
    }) {}
    
    console.log(FastCheck.sample(Arbitrary.make(Class), 5))
    /*
    Example Output:
    [
      Class { a: 2.6624670822171524e-44 },
      Class { a: 3.4028177873105996e+38 },
      Class { a: 3.402820626847944e+38 },
      Class { a: 3.783505853677006e-44 },
      Class { a: 3243685 }
    ]
    */

    After

    Now, the values respect the arbitrary annotation and return the expected constant:

    import { Arbitrary, FastCheck, Schema } from "effect"
    
    class Class extends Schema.Class<Class>("Class")({
      a: Schema.NumberFromString.annotations({
        arbitrary: () => (fc) => fc.constant(1)
      })
    }) {}
    
    console.log(FastCheck.sample(Arbitrary.make(Class), 5))
    /*
    [
      Class { a: 1 },
      Class { a: 1 },
      Class { a: 1 },
      Class { a: 1 },
      Class { a: 1 }
    ]
    */

Don't miss a new effect release

NewReleases is sending notifications on new releases.