Version 3.x, register Arbitraries directly with ArbMap
See original GitHub issueFeature
I love the move to ArbMap in v3, over the thread-level registry.
It’d be great if we could directly register Arbitrary instances with ArbMap instead of needing an intermediary type with static members.
For example
let customArb = //...
ArbMap.defaults |> ArbMap.with customArb
This would allow users to simply define and use an Arbitrary all in one local scope. This seems especially relevant now that ArbMap enables users to override type generation in a limited scope. It seems likely users would define an arbitrary only meant to be used in constructing some parent arbitrary.
Implementation Ideas
It seems TypeClass currently bears the responsibility for tracking the map of types to Arbitrary instances, and it tracks them as Map<InstanceKind,MethodInfo>
.
In order to directly register Arbitraries, this map would need to change.
I haven’t quite grasped TypeClass yet, but here’s my idea.
- It makes sense to me that ArbMap is responsible for tracking instances of arbitraries, maybe
Map<InstanceKind,IArbitrary>
. - TypeClass can be responsible for knowing what a match looks like / the light construction it seems to do
- maybe
arbMap |> TypeClass.getInstance type
- maybe
- Discovery then also probably moves somewhere else, and it outputs an ArbMap
- maybe
let arbMap = Discover.factoriesOnType<type>
(or maybe it outputs aMap<Type, IArbitrary>
) - If we don’t want to invoke the factories right away, then we could create some internal lazy Arbitrary derivative that invokes the matched static factory on first call
- maybe
Issue Analytics
- State:
- Created a year ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
I think the work is ready for review. I’ve experimented with both the Fluent and FSharp APIs, and it seems to work as I expect. I added tests for any errors I found.
The public endpoint names may need some tweaking
Ah. I see how I misread your earlier comment.
I think you’re correct, but I also think the category of arbitraries made from other generators and arbitraries is a pretty significant category. The library offers a pretty robust set of building blocks.