Hyperlinkv0.8.0-beta.28

Schema

Schema.makeIsBetweenfunctioneffect/Schema.ts:7248
<T>(deriveOptions: {
  readonly order: Order.Order<T>
  readonly annotate?:
    | ((options: {
        readonly minimum: T
        readonly maximum: T
        readonly exclusiveMinimum?: boolean | undefined
        readonly exclusiveMaximum?: boolean | undefined
      }) => Annotations.Filter)
    | undefined
  readonly formatter?: Formatter<T> | undefined
}): (
  options: {
    readonly minimum: T
    readonly maximum: T
    readonly exclusiveMinimum?: boolean | undefined
    readonly exclusiveMaximum?: boolean | undefined
  },
  annotations?: Annotations.Filter
) => SchemaAST.Filter<T>

Creates an inclusive or exclusive range check for any ordered type from an Order.Order instance.

Order checks
Source effect/Schema.ts:724848 lines
export function makeIsBetween<T>(deriveOptions: {
  readonly order: Order.Order<T>
  readonly annotate?:
    | ((options: {
      readonly minimum: T
      readonly maximum: T
      readonly exclusiveMinimum?: boolean | undefined
      readonly exclusiveMaximum?: boolean | undefined
    }) => Annotations.Filter)
    | undefined
  readonly formatter?: Formatter<T> | undefined
}) {
  const greaterThanOrEqualTo = Order.isGreaterThanOrEqualTo(deriveOptions.order)
  const greaterThan = Order.isGreaterThan(deriveOptions.order)
  const lessThanOrEqualTo = Order.isLessThanOrEqualTo(deriveOptions.order)
  const lessThan = Order.isLessThan(deriveOptions.order)
  const formatter = deriveOptions.formatter ?? format
  return (options: {
    readonly minimum: T
    readonly maximum: T
    readonly exclusiveMinimum?: boolean | undefined
    readonly exclusiveMaximum?: boolean | undefined
  }, annotations?: Annotations.Filter) => {
    const gte = options.exclusiveMinimum ? greaterThan : greaterThanOrEqualTo
    const lte = options.exclusiveMaximum ? lessThan : lessThanOrEqualTo
    return makeFilter<T>(
      (input) => gte(input, options.minimum) && lte(input, options.maximum),
      {
        expected: `a value between ${formatter(options.minimum)}${options.exclusiveMinimum ? " (excluded)" : ""} and ${
          formatter(options.maximum)
        }${options.exclusiveMaximum ? " (excluded)" : ""}`,
        arbitrary: {
          constraint: {
            ordered: {
              order: deriveOptions.order,
              minimum: options.minimum,
              maximum: options.maximum,
              ...(options.exclusiveMinimum && { exclusiveMinimum: true }),
              ...(options.exclusiveMaximum && { exclusiveMaximum: true })
            }
          }
        },
        ...deriveOptions.annotate?.(options),
        ...annotations
      }
    )
  }
}
Referenced by 4 symbols