spire icon indicating copy to clipboard operation
spire copied to clipboard

Provide extractors for intervals

Open rklaehn opened this issue 10 years ago • 1 comments
trafficstars

It would be good to have an easy way to access the maximum and minimum value in the very common case of bounded intervals.

@AlecZorab requested this on gitter. Maybe add extractor objects to spire.math.Interval.

@non Should there be extractor objects for all possible cases, or just for extracting the minimum and maximum in case of a fully bounded interval?

rklaehn avatar Jul 08 '15 12:07 rklaehn

did anything happen to this @rklaehn ?

I am trying to use the Interval and Bound class, for now I am only working on Int. Just to makes things work, now I am doing this crazy thing:

  def boundValue(bound: Bound[A])(implicit ev: A =:= Int): Int = bound match {
    case Open(a)      => a
    case Closed(a)    => a
    case EmptyBound() => 0
    case Unbound()    => Int.MaxValue
  }

Is there a better way? I don't have much experience with this kind of api, but found the Interval class quite useful :-)

scalavision avatar Jul 17 '20 20:07 scalavision