MCPcopy Create free account
hub / github.com/Effect-TS/effect / collectionArbitrary

Function collectionArbitrary

packages/effect/src/Schema.ts:11021–11059  ·  view source on GitHub ↗
(
  fc: typeof FastCheck,
  ctx: Annotations.ToArbitrary.Context,
  item: FastCheck.Arbitrary<T>,
  terminalItem: FastCheck.Arbitrary<T> | undefined,
  fromIterable: (items: Array<T>) => Out,
  comparator?: ((a: T, b: T) => boolean) | undefined
)

Source from the content-addressed store, hash-verified

11019}
11020
11021function collectionArbitrary<T, Out>(
11022 fc: typeof FastCheck,
11023 ctx: Annotations.ToArbitrary.Context,
11024 item: FastCheck.Arbitrary<T>,
11025 terminalItem: FastCheck.Arbitrary<T> | undefined,
11026 fromIterable: (items: Array<T>) => Out,
11027 comparator?: ((a: T, b: T) => boolean) | undefined
11028) {
11029 const constraint = ctx.constraint
11030 const constraints = constraint === undefined ||
11031 (constraint.minLength === undefined && constraint.maxLength === undefined)
11032 ? undefined
11033 : {
11034 ...(constraint.minLength !== undefined ? { minLength: constraint.minLength } : {}),
11035 ...(constraint.maxLength !== undefined ? { maxLength: constraint.maxLength } : {})
11036 }
11037 if (
11038 constraints?.minLength !== undefined && constraints.maxLength !== undefined &&
11039 constraints.minLength > constraints.maxLength
11040 ) {
11041 throw new globalThis.Error("Unable to derive an arbitrary for size constraints")
11042 }
11043 const minLength = constraints?.minLength ?? 0
11044 const terminal = minLength === 0
11045 ? fc.constant<Array<T>>([])
11046 : terminalItem === undefined
11047 ? undefined
11048 : arrayFromItems(fc, terminalItem, { ...constraints, maxLength: minLength }, comparator)
11049 const arrays = withRecursion(
11050 fc,
11051 ctx,
11052 terminal,
11053 arrayFromItems(fc, item, constraints, comparator)
11054 )
11055 return {
11056 arbitrary: arrays.arbitrary.map(fromIterable),
11057 terminal: arrays.terminal?.map(fromIterable)
11058 }
11059}
11060
11061function entriesArbitrary<K, V, Out>(
11062 fc: typeof FastCheck,

Callers 4

entriesArbitraryFunction · 0.85
ReadonlySetFunction · 0.85
HashSetFunction · 0.85
ChunkFunction · 0.85

Calls 3

arrayFromItemsFunction · 0.85
withRecursionFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected