Hyperlinkv0.8.0-beta.28

Order

Order.isBetweenconsteffect/Order.ts:926
<A>(O: Order<A>): {
  (options: { minimum: A; maximum: A }): (self: A) => boolean
  (self: A, options: { minimum: A; maximum: A }): boolean
}

Checks whether a value is between a minimum and a maximum (inclusive) according to the given order.

When to use

Use when you need range checks that respect domain-specific ordering, such as dates, versions, or custom priorities, instead of JavaScript numeric comparison.

Details

Returns true when the value is greater than or equal to minimum and less than or equal to maximum. Values outside the range return false. Both bounds are inclusive.

Example (Checking ranges)

import { Order } from "effect"

const betweenNumber = Order.isBetween(Order.Number)

console.log(betweenNumber(5, { minimum: 1, maximum: 10 })) // true
console.log(betweenNumber(1, { minimum: 1, maximum: 10 })) // true
console.log(betweenNumber(10, { minimum: 1, maximum: 10 })) // true
console.log(betweenNumber(0, { minimum: 1, maximum: 10 })) // false
console.log(betweenNumber(11, { minimum: 1, maximum: 10 })) // false
Source effect/Order.ts:92617 lines
export const isBetween = <A>(O: Order<A>): {
  (options: {
    minimum: A
    maximum: A
  }): (self: A) => boolean
  (self: A, options: {
    minimum: A
    maximum: A
  }): boolean
} =>
  dual(
    2,
    (self: A, options: {
      minimum: A
      maximum: A
    }): boolean => !isLessThan(O)(self, options.minimum) && !isGreaterThan(O)(self, options.maximum)
  )
Referenced by 4 symbols