scala-library-next icon indicating copy to clipboard operation
scala-library-next copied to clipboard

Consider an Interval type in the core lib

Open benhutchison opened this issue 4 years ago • 0 comments

The idea of an interval is central to a large portion of programming logic.

Please consider defining a bounded or half-open interval type in the core Scala lib. Currently, the choices are

  • Use a tuple (n1, n2). The intent isn't clear and there's no enforcement of invariants that n needs to be ordered and n1 < n2.
  • Use a library like Spire or Continuuum. This is a heavy dependency bringing a lot of baggage if all you wanted was to express simple business logic like eg "Item count must be between 1 and 5".

Note that Range is a distinct if related idea; an enumerable sequence of integers. Intervals can be defined over a wider set of types, and need not be enumerable.

benhutchison avatar Feb 24 '21 23:02 benhutchison