Skip to content

Commit

Permalink
add interval tuple properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bvenn committed Jul 20, 2023
1 parent 7de8b82 commit 0ddb8b7
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/FSharp.Stats/Intervals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open System

module Intervals =

/// Closed interval [Start,End]
type Interval<'a> =
| ClosedInterval of 'a * 'a
Expand All @@ -18,7 +19,30 @@ module Intervals =
| ClosedInterval (_,max) -> Some max
| Empty -> None

static member inline Create (min,max) = ClosedInterval (min,max)
member inline this.TryToTuple =
match this with
| ClosedInterval (min,max) -> Some (min,max)
| Empty -> None

member inline this.ToTuple() =
match this with
| ClosedInterval (min,max) -> (min,max)
| Empty -> failwithf "Interval was empty!"

member inline this.GetStart() =
match this with
| ClosedInterval (min,_) -> min
| Empty -> failwithf "Interval was empty!"

member inline this.GetEnd() =
match this with
| ClosedInterval (_,max) -> max
| Empty -> failwithf "Interval was empty!"

static member inline Create (min,max) =
if min > max then failwithf "Interval start must be lower than interval end!"
ClosedInterval (min,max)


/// Creates closed interval [min,max] by given min and max
let inline create min max =
Expand Down Expand Up @@ -190,7 +214,11 @@ module Intervals =
| ClosedInterval (min,max) -> value >= min && value <= max
| Empty -> false


type Intervals<'a> =

static member a = 2.


// ####################################################

// interval tree
Expand Down

0 comments on commit 0ddb8b7

Please sign in to comment.