You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 27, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -205,6 +205,28 @@ let! myVal =
205
205
|> GenX.autoWith<MyType>
206
206
```
207
207
208
+
**Register generators for generic types in `AutoGenConfig`:**
209
+
210
+
```f#
211
+
// An example of a generic type
212
+
type Maybe<'a> = Just of 'a | Nothing
213
+
214
+
// a type containing generators for generic types
215
+
// methods should return Gen<_> and are allowed to take Gen<_> and AutoGenConfig as parameters
216
+
type GenericGenerators =
217
+
// Generator for Maybe<'a>
218
+
static member MaybeGen<'a>(valueGen : Gen<'a>) : Gen<Maybe<'a>> =
219
+
Gen.frequency [
220
+
1, Gen.constant None
221
+
8, valueGen
222
+
]
223
+
224
+
let! myVal =
225
+
GenX.defaults
226
+
|> AutoGenConfig.addGenerators<GenericGenerators>
227
+
|> GenX.autoWith<Maybe<int>>
228
+
```
229
+
208
230
If you’re not happy with the auto-gen defaults, you can of course create your own generator that calls `GenX.autoWith` with your chosen config and use that everywhere.
Copy file name to clipboardExpand all lines: src/Hedgehog.Experimental/GenX.fs
+20-11Lines changed: 20 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -368,7 +368,7 @@ module GenX =
368
368
array.SetValue(en.Current, currentIndices)
369
369
| currentLength :: remainingLengths ->
370
370
for i in0..currentLength -1do
371
-
currentIndices.[currentDimensionIndex]<- i
371
+
currentIndices[currentDimensionIndex]<- i
372
372
loop (currentDimensionIndex +1) remainingLengths
373
373
loop 0 lengths
374
374
array
@@ -385,11 +385,15 @@ module GenX =
385
385
letaddGenMsg="You can use 'GenX.defaults |> AutoGenConfig.addGenerator myGen |> GenX.autoWith' to generate types not inherently supported by GenX.auto."
386
386
letunsupportedTypeException= NotSupportedException (sprintf "Unable to auto-generate %s. %s" typeof<'a>.FullName addGenMsg)
387
387
388
+
// Prevent auto-generating AutoGenConfig itself - it should only be passed as a parameter
389
+
if typeof<'a>= typeof<AutoGenConfig>then
390
+
raise (NotSupportedException "Cannot auto-generate AutoGenConfig type. It should be provided as a parameter to generator methods.")
391
+
388
392
letgenPoco(shape:ShapePoco<'a>)=
389
393
letbestCtor=
390
394
shape.Constructors
391
-
|> Seq.filter (fun c -> c.IsPublic)
392
-
|> Seq.sortBy (fun c -> c.Arity)
395
+
|> Seq.filter _.IsPublic
396
+
|> Seq.sortBy _.Arity
393
397
|> Seq.tryHead
394
398
395
399
match bestCtor with
@@ -458,10 +462,10 @@ module GenX =
458
462
if arg.IsGenericParameter then
459
463
typeArgs
460
464
|> Array.tryFind (fun p -> p.argTypeDefinition.Name = arg.Name)
0 commit comments