Logo GenPRES

ValueUnit Module

Creates a ValueUnit, converts it between units, calculates with and compares ValueUnits with unit simplification, and formats and parses a ValueUnit.

Nested modules

Modules Description

Dto

Maps a ValueUnit to a Dto with the values, the unit and the group as text, and back. The mapping to a Dto gives None for a language other than English or Dutch. The mapping back reads the unit from the Json text when the Dto has one, and otherwise parses the unit with its group: a blank unit gives None, an unknown unit with no group or the group General becomes a General unit, and an unknown unit with another group raises a FormatException.

Group

Exposes the Group type and the functions of the Group module under the older name ValueUnit.Group, so code that uses the older name keeps compiling. The module is a full module rather than a module abbreviation, so that its members are exported to other assemblies.

Multipliers

Holds the multiplier of every unit to its base unit and converts a value between a unit and the base unit.

Operators

Holds the infix operators to calculate with, compare and convert ValueUnits.

Functions and values

Function or value Description

applyToValue fValue vu

Full Usage: applyToValue fValue vu

Parameters:
Returns: ValueUnit The updated ValueUnit

Apply a function fValue to the Value of a ValueUnit vu

fValue : BigRational[] -> RationalX[]

The function to apply to the Value

vu : ValueUnit

The ValueUnit

Returns: ValueUnit

The updated ValueUnit

Example

 let fValue = Array.map ((+) 1N) // add 1 to each value
 applyToValue fValue (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) =
 ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N))
val fValue: (obj array -> obj array)
module Array from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array

build ns ds (isCount, u)

Full Usage: build ns ds (isCount, u)

Parameters:
Returns: bool * Unit

Build a unit from a list of numerators and denominators. Uses an accumulator to build the unit and a boolean to indicate whether there is a count unit in the numerator. isCount is true when there is a count unit in the numerator and false when there is no count unit in the numerator. Note when ns = ds then the result is isCount = true and u = NoUnit

ns : Unit list
ds : Unit list
isCount : bool
u : Unit
Returns: bool * Unit

calc b op vu1 vu2

Full Usage: calc b op vu1 vu2

Parameters:
Returns: ValueUnit The result of applying the operator to the ValueUnits

Calculate a ValueUnit by applying an operator op to ValueUnit vu1 and vu2. The operator can be addition, subtraction, multiplication or division. The boolean b results in whether the result is simplified.

fails when adding or subtracting different units

b : bool

Whether to simplify the result

op : BigRational -> BigRational -> BigRational

The operator to apply

vu1 : ValueUnit

The first ValueUnit

vu2 : ValueUnit

The second ValueUnit

Returns: ValueUnit

The result of applying the operator to the ValueUnits

Example

 calc true (+) (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) =
 ValueUnit ([|2N; 3N; 4N; 5N; 6N|], Mass (KiloGram 1N))

cmp cp vu1 vu2

Full Usage: cmp cp vu1 vu2

Parameters:
Returns: bool True if the comparison is true, false otherwise

Compare a ValueUnit vu1 with vu2.Comparison can be: greater, greater or equal, smaller, smaller or equal.

Checks if the comparison is true for all individual values. Doesn't work for equal.

cp : BigRational -> BigRational -> bool

The operator to use

vu1 : ValueUnit

The first ValueUnit

vu2 : ValueUnit

The second ValueUnit

Returns: bool

True if the comparison is true, false otherwise

Example

 // 1 kg > 1000 g = true
 cmp (>) (ValueUnit ([|1N|], Mass (KiloGram 1N))) (ValueUnit ([|10N|], Mass (Gram 1N))) = true

cmpToStr cp

Full Usage: cmpToStr cp

Parameters:
Returns: string

Returns a string representation of a ValueUnit comparing operator. When the operator is unknown, "unknown comparison" is returned.

cp : ValueUnit -> ValueUnit -> bool
Returns: string
Example

 cmpToStr (>) = ">"

containsValue vu2 vu1

Full Usage: containsValue vu2 vu1

Parameters:
    vu2 : ValueUnit - The ValueUnit to check
    vu1 : ValueUnit - The ValueUnit that should contain vu2

Returns: bool

Check if ValueUnit vu1 contains ValueUnit vu2.

vu2 : ValueUnit

The ValueUnit to check

vu1 : ValueUnit

The ValueUnit that should contain vu2

Returns: bool
Example

 // returns true
 containsValue (ValueUnit ([|2N; 3N|], Mass (KiloGram 1N))) (ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N)))
 // returns true
 containsValue (ValueUnit ([|2000N; 3000N|], Mass (Gram 1N))) (ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N)))
 // returns false
 containsValue (ValueUnit ([|2N; 3N|], Mass (Gram 1N))) (ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N)))

convertTo u vu

Full Usage: convertTo u vu

Parameters:
Returns: ValueUnit

Convert a ValueUnit vu to a unit u. Do not convert to no unit or zerounit

u : Unit
vu : ValueUnit
Returns: ValueUnit
Example

 //For example 1 gram -> 1000 mg:
 ValueUnit([|1N|], Units.Mass.gram) |> convertTo Units.Mass.milliGram

count

Full Usage: count

Returns: Unit
Returns: Unit

create u v

Full Usage: create u v

Parameters:
Returns: ValueUnit

Create a ValueUnit from a value v (a bigrational array) and a unit u

u : Unit
v : RationalX[]
Returns: ValueUnit
Example

create (Mass (KiloGram 1N)) [| 1N; 2N; 3N |] = ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))

createCombiUnit (arg1, arg1, arg1)

Full Usage: createCombiUnit (arg1, arg1, arg1)

Parameters:
Returns: Unit
arg0 : Unit
arg1 : Operator
arg2 : Unit
Returns: Unit

createSingle u v

Full Usage: createSingle u v

Parameters:
Returns: ValueUnit

Create a ValueUnit from a single value v and a unit u

u : Unit
v : RationalX
Returns: ValueUnit
Example

createSingle (Mass (KiloGram 1N)) 1N = ValueUnit ([|1N|], Mass (KiloGram 1N))

denominator

Full Usage: denominator

Returns: ValueUnit -> bigint array

Get the denominators of the value of a ValueUnit.

Returns: ValueUnit -> bigint array
Example

 // returns 2, 3, 5
 denominator (ValueUnit ([|1N/2N; 2N/3N; 3N/5N|], Mass (KiloGram 1N)))

empty

Full Usage: empty

Returns: ValueUnit

An empty ValueUnit that has no value and no unit, i.e. an empty array with NoUnit.

Returns: ValueUnit

eqs vu1 vu2

Full Usage: eqs vu1 vu2

Parameters:
Returns: bool

Determine if vu1 equals vu2. This is true when both ValueUnits have the same unit and the same value

vu1 : ValueUnit

The first ValueUnit

vu2 : ValueUnit

The second ValueUnit

Returns: bool

eqsGroup vu1 vu2

Full Usage: eqsGroup vu1 vu2

Parameters:
Returns: bool

Checks whether vu1 is of the same unit group as vu2

vu1 : ValueUnit
vu2 : ValueUnit
Returns: bool

filter pred

Full Usage: filter pred

Parameters:
Returns: ValueUnit -> ValueUnit

Filter the value of a value unit using a predicate function pred. This function is parameterized on the base value of the value unit.

pred : BigRational -> bool
Returns: ValueUnit -> ValueUnit
Example

 // Get all even numbers, note that the base value of 1 KiloGram is 1000
 // so the predicate function is applied to 1000, 2000, 3000, etc.
 // ValueUnit = ValueUnit ([|-2N; 2N|], Mass (KiloGram 1N))
 filter (fun br -> (br / 2000N).Denominator = 1I) (ValueUnit ([|1N; 2N; 3N; -1N; -2N; -3N|], Mass (KiloGram 1N)))

filterValues fPred

Full Usage: filterValues fPred

Parameters:
    fPred : BigRational -> bool - The predicate function to use

Returns: ValueUnit -> ValueUnit

Filter the values in a ValueUnit using a predicate function pred.

fPred : BigRational -> bool

The predicate function to use

Returns: ValueUnit -> ValueUnit

fromString s

Full Usage: fromString s

Parameters:
    s : string

Returns: Result<ValueUnit, string>

Parse a string into a ValueUnit

s : string
Returns: Result<ValueUnit, string>
Example

 // returns Success: ValueUnit ([|3N|], Volume (MilliLiter 1N))
 fromString "3 mL[Volume]"

 // returns Success: ValueUnit ([|3N|], CombiUnit (Volume (MilliLiter 1N), OpPer, Time (Minute 1N)))
 fromString "3 mL/min" = ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))

generalSingleValueUnit v n s

Full Usage: generalSingleValueUnit v n s

Parameters:
Returns: ValueUnit

Create a general 'single' ValueUnit with unit value n general text s and single value v

v : RationalX
n : BigRational
s : string
Returns: ValueUnit

generalUnit n s

Full Usage: generalUnit n s

Parameters:
Returns: Unit

create a general unit with unit value n and string s

n : BigRational
s : string
Returns: Unit

generalValueUnit v n s

Full Usage: generalValueUnit v n s

Parameters:
Returns: ValueUnit

Create a general ValueUnit with unit value n general text s and value v

v : RationalX[]
n : BigRational
s : string
Returns: ValueUnit

get arg1

Full Usage: get arg1

Parameters:
Returns: BigRational[] * Unit

Get the value and the unit of a ValueUnit as a tuple. Example: get (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) = ([|1N; 2N; 3N|], Mass (KiloGram 1N))

arg0 : ValueUnit
Returns: BigRational[] * Unit

getBaseValue

Full Usage: getBaseValue

Returns: ValueUnit -> BigRational[]

Get the Value of a ValueUnit vu as the base value

Returns: ValueUnit -> BigRational[]
Example

 ValueUnit([|1N|], Units.Mass.kiloGram) |> getBaseValue = [|1000N|]

getGroup

Full Usage: getGroup

Returns: ValueUnit -> Group

Get the full unit group of a ValueUnit. Example: getGroup (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) = MassGroup

Returns: ValueUnit -> Group

getIndices vu1 vu2

Full Usage: getIndices vu1 vu2

Parameters:
Returns: int array

Get the indices of the values in vu1 that are also in vu2

vu1 : ValueUnit
vu2 : ValueUnit
Returns: int array

getUnit arg1

Full Usage: getUnit arg1

Parameters:
Returns: Unit

Get the unit of a ValueUnit

arg0 : ValueUnit
Returns: Unit

getUnits u

Full Usage: getUnits u

Parameters:
Returns: Unit list

Get a list of the units in a unit u

u : Unit
Returns: Unit list

getValue arg1

Full Usage: getValue arg1

Parameters:
Returns: BigRational[]

Get the value of a ValueUnit. Example: getValue (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) = [|1N; 2N; 3N|]

arg0 : ValueUnit
Returns: BigRational[]

gt

Full Usage: gt

Returns: ValueUnit -> ValueUnit -> bool

Check if first ValueUnit is greater than second ValueUnit Example: gt (ValueUnit ([|1N |], Mass (KiloGram 1N))) (ValueUnit ([|10N|], Mass (Gram 1N))) = true

Returns: ValueUnit -> ValueUnit -> bool

gtZero

Full Usage: gtZero

Returns: ValueUnit -> bool

Check if Value is > 0

Returns: ValueUnit -> bool

gte

Full Usage: gte

Returns: ValueUnit -> ValueUnit -> bool

Check if first ValueUnit is greater than or equal to second ValueUnit Example: gte (ValueUnit ([|1N |], Mass (KiloGram 1N))) (ValueUnit ([|10N|], Mass (Gram 1N))) = true

Returns: ValueUnit -> ValueUnit -> bool

gteZero

Full Usage: gteZero

Returns: ValueUnit -> bool

Check if Value >= 0

Returns: ValueUnit -> bool

hasNoUnit

Full Usage: hasNoUnit

Returns: ValueUnit -> bool
Returns: ValueUnit -> bool

hasUnit u2 u1

Full Usage: hasUnit u2 u1

Parameters:
Returns: bool

Checks wheter u1 has a unit u2

u2 : Unit
u1 : Unit
Returns: bool

hasZeroUnit

Full Usage: hasZeroUnit

Returns: ValueUnit -> bool
Returns: ValueUnit -> bool

intersect vu1 vu2

Full Usage: intersect vu1 vu2

Parameters:
Returns: ValueUnit

Get the intersection of two ValueUnits.

vu1 : ValueUnit

ValueUnit 1

vu2 : ValueUnit

ValueUnit 2

Returns: ValueUnit
Example

 // returns ValueUnit ([|2N; 3N|], Mass (KiloGram 1N))
 intersect (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) (ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N)))

isCountUnit

Full Usage: isCountUnit

Returns: Unit -> bool

Check whether the unit is a count unit, i.e. belongs to the Count group

Returns: Unit -> bool

isEmpty

Full Usage: isEmpty

Returns: ValueUnit -> bool

Checks whether a ValueUnit has an empty value

Returns: ValueUnit -> bool

isSingleValue

Full Usage: isSingleValue

Returns: ValueUnit -> bool

Check whether a ValueUnit is a single value

Returns: ValueUnit -> bool

isSubset vu1 vu2

Full Usage: isSubset vu1 vu2

Parameters:
    vu1 : ValueUnit - ValueUnit 1 the possible subset
    vu2 : ValueUnit - ValueUnit 2 the set to check against

Returns: bool

Check if a ValueUnit is a subset of another ValueUnit.

vu1 : ValueUnit

ValueUnit 1 the possible subset

vu2 : ValueUnit

ValueUnit 2 the set to check against

Returns: bool
Example

 // returns true
 isSubset (ValueUnit ([|2N; 3N|], Mass (KiloGram 1N))) (ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N)))
 // returns false
 isSubset (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) (ValueUnit ([|2N; 3N; 4N|], Mass (KiloGram 1N)))

isZero

Full Usage: isZero

Returns: ValueUnit -> bool

Check if Value is zero

Returns: ValueUnit -> bool

mapValues fMap

Full Usage: mapValues fMap

Parameters:
Returns: ValueUnit -> ValueUnit

Map the values in a ValueUnit using a function fMap.

fMap : BigRational -> RationalX

The function to appy to each individual value

Returns: ValueUnit -> ValueUnit

maxExclMultipleOf incr vu

Full Usage: maxExclMultipleOf incr vu

Parameters:
Returns: ValueUnit

Calculate the maximum value of a ValueUnit that is a maximum exclusive and is a multiple of Increment.

incr : ValueUnit

The Increment

vu : ValueUnit

The ValueUnit

Returns: ValueUnit
Example

 maxExclMultipleOf (ValueUnit ([|3N|], Mass (Gram 1N))) (ValueUnit ([|9N|], Mass (Gram 1N))) =
 ValueUnit ([|6N|], Mass (Gram 1N))

maxInclMultipleOf incr vu

Full Usage: maxInclMultipleOf incr vu

Parameters:
Returns: ValueUnit

Calculate the maximum value of a ValueUnit that is a maximum inclusive and is a multiple of Increment.

incr : ValueUnit

The Increment

vu : ValueUnit

The ValueUnit

Returns: ValueUnit
Example

 maxInclMultipleOf (ValueUnit ([|3N|], Mass (Gram 1N))) (ValueUnit ([|8N|], Mass (Gram 1N))) =
 ValueUnit ([|6N|], Mass (Gram 1N))

maxValue vu

Full Usage: maxValue vu

Parameters:
Returns: ValueUnit option

Get the largest value of a ValueUnit. Returns None if the ValueUnit is empty.

vu : ValueUnit
Returns: ValueUnit option

medianValue vu

Full Usage: medianValue vu

Parameters:
Returns: ValueUnit option

Get the median value of a ValueUnit. Returns None if empty.

For an even-length value set this returns the upper-middle element (the value at sorted index length / 2), NOT the average of the two middle values.

vu : ValueUnit
Returns: ValueUnit option

minExclMultipleOf incr vu

Full Usage: minExclMultipleOf incr vu

Parameters:
Returns: ValueUnit

Calculate the minimum value of a ValueUnit that is a minimum exclusive and is a multiple of Increment.

incr : ValueUnit

The Increment

vu : ValueUnit

The ValueUnit

Returns: ValueUnit
Example

 minExclMultipleOf (ValueUnit ([|3N|], Mass (Gram 1N))) (ValueUnit ([|4N|], Mass (Gram 1N))) =
 ValueUnit ([|6N|], Mass (Gram 1N))

minInclMultipleOf incr vu

Full Usage: minInclMultipleOf incr vu

Parameters:
Returns: ValueUnit

Calculate the minimum value of a ValueUnit that is a minimum inclusive and is a multiple of Increment.

incr : ValueUnit

The Increment

vu : ValueUnit

The ValueUnit

Returns: ValueUnit
Example

 minInclMultipleOf (ValueUnit ([|3N|], Mass (Gram 1N))) (ValueUnit ([|4N|], Mass (Gram 1N))) =
 ValueUnit ([|6N|], Mass (Gram 1N))

minValue vu

Full Usage: minValue vu

Parameters:
Returns: ValueUnit option

Get the smallest value of a ValueUnit. Returns None if the ValueUnit is empty.

vu : ValueUnit
Returns: ValueUnit option

minus u2 u1

Full Usage: minus u2 u1

Parameters:
Returns: Unit
u2 : Unit
u1 : Unit
Returns: Unit

notCombiUnit u

Full Usage: notCombiUnit u

Parameters:
Returns: bool

Checks whether unit u is not a CombiUnit

u : Unit
Returns: bool

numerator

Full Usage: numerator

Returns: ValueUnit -> bigint array

Get the numerators of the value of a ValueUnit.

Returns: ValueUnit -> bigint array
Example

 // returns 1, 2, 3
 numerator (ValueUnit ([|1N/2N; 2N/3N; 3N/5N|], Mass (KiloGram 1N)))

one u

Full Usage: one u

Parameters:
Returns: ValueUnit

Create a 'one' with unit u

u : Unit
Returns: ValueUnit

opFromString

Full Usage: opFromString

Returns: string -> Operator
Returns: string -> Operator

opToStr

Full Usage: opToStr

Returns: Operator -> string
Returns: Operator -> string

parse s

Full Usage: parse s

Parameters:
    s : string

Returns: ParserResult<ValueUnit, unit>

Parse a string to a ValueUnit.

s : string
Returns: ParserResult<ValueUnit, unit>

per u2 u1

Full Usage: per u2 u1

Parameters:
Returns: Unit
u2 : Unit
u1 : Unit
Returns: Unit

pickIndices indices vu

Full Usage: pickIndices indices vu

Parameters:
Returns: ValueUnit
indices : int array
vu : ValueUnit
Returns: ValueUnit

pickNearestHigherElseLower target candidates

Full Usage: pickNearestHigherElseLower target candidates

Parameters:
Returns: ValueUnit
target : ValueUnit
candidates : ValueUnit
Returns: ValueUnit

plus u2 u1

Full Usage: plus u2 u1

Parameters:
Returns: Unit
u2 : Unit
u1 : Unit
Returns: Unit

removeBigRationalMultiples

Full Usage: removeBigRationalMultiples

Returns: ValueUnit -> ValueUnit

Remove all big rational multiples of the value of a ValueUnit.

Returns: ValueUnit -> ValueUnit
Example

 // returns ValueUnit ([|2N; 3N; 5N; 7N|], Mass (KiloGram 1N))
 removeBigRationalMultiples (ValueUnit ([|2N..1N..10N|], Mass (KiloGram 1N)))

setSingleValue v

Full Usage: setSingleValue v

Parameters:
Returns: ValueUnit -> ValueUnit

Sets a single value to a ValueUnit. Example: ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N)) |> setSingleValue 1N = ValueUnit ([|1N|], Mass (KiloGram 1N))

v : RationalX
Returns: ValueUnit -> ValueUnit

setUnit u vu

Full Usage: setUnit u vu

Parameters:
Returns: ValueUnit

Set the unit of a ValueUnit, keeping its value

u : Unit
vu : ValueUnit
Returns: ValueUnit

setValue v arg2

Full Usage: setValue v arg2

Parameters:
Returns: ValueUnit

Just sets a value without calculation. Example: ValueUnit ([|1N|], Mass (KiloGram 1N)) |> setValue [| 1N; 2N; 3N |] = ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))

v : RationalX[]
arg1 : ValueUnit
Returns: ValueUnit

setZeroOrPositive vu

Full Usage: setZeroOrPositive vu

Parameters:
Returns: ValueUnit

Make sure that a ValueUnit has a positive value or zero. NoUnit is transformed to ZeroUnit to enable logic for calculation of min and max values. If a ValueUnit has a Value then all negative or zero values are removed.

vu : ValueUnit
Returns: ValueUnit

simplify vu

Full Usage: simplify vu

Parameters:
    vu : ValueUnit - The value unit to simplify

Returns: ValueUnit The simplified value unit

Simplify a value unit u such that units are algebraically removed or transformed to count units, where applicable.

vu : ValueUnit

The value unit to simplify

Returns: ValueUnit

The simplified value unit

Example

 simplify (ValueUnit ([|1N; 2N; 3N|], CombiUnit (Mass (KiloGram 1N), OpPer, Volume (Liter 1N)))) =
 ValueUnit ([|1N; 2N; 3N|], CombiUnit (Mass (KiloGram 1N), OpPer, Volume (Liter 1N)))
 simplify (ValueUnit ([|1N; 2N; 3N|], CombiUnit (Mass (KiloGram 1N), OpPer, Mass (KiloGram 1N)))) =
 ValueUnit ([|1N; 2N; 3N|], Count (Times 1N))

simplifyUnit u

Full Usage: simplifyUnit u

Parameters:
    u : Unit - The unit to simplify

Returns: Unit The simplified unit

Simplify a unit u such that units are algebraically removed or transformed to count units, where applicable.

u : Unit

The unit to simplify

Returns: Unit

The simplified unit

singleWithUnit u v

Full Usage: singleWithUnit u v

Parameters:
Returns: ValueUnit

Utility create function to allow piping with a single value v |> WithUnit u

u : Unit
v : RationalX
Returns: ValueUnit
Example

1N |> singleWithUnit (Mass (KiloGram 1N)) = ValueUnit ([|1N|], Mass (KiloGram 1N))

singleWithValue v u

Full Usage: singleWithValue v u

Parameters:
Returns: ValueUnit

create a ValueUnit with syntax like u |> withValue v, where v is a single value

v : RationalX
u : Unit
Returns: ValueUnit
Example

(Mass (KiloGram 1N)) |> withSingleValue 1N = ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))

st

Full Usage: st

Returns: ValueUnit -> ValueUnit -> bool

Check if first ValueUnit is smaller than second ValueUnit Example: st (ValueUnit ([|1N |], Mass (KiloGram 1N))) (ValueUnit ([|10N|], Mass (Gram 1N))) = false

Returns: ValueUnit -> ValueUnit -> bool

stZero

Full Usage: stZero

Returns: ValueUnit -> bool

Check if Value < 0

Returns: ValueUnit -> bool

ste

Full Usage: ste

Returns: ValueUnit -> ValueUnit -> bool

Check if first ValueUnit is smaller than or equal to second ValueUnit Example: ste (ValueUnit ([|1N |], Mass (KiloGram 1N))) (ValueUnit ([|10N|], Mass (Gram 1N))) = false

Returns: ValueUnit -> ValueUnit -> bool

steZero

Full Usage: steZero

Returns: ValueUnit -> bool

Check if Value <= 0

Returns: ValueUnit -> bool

takeFirst n

Full Usage: takeFirst n

Parameters:
    n : int - The n elements to take

Returns: ValueUnit -> ValueUnit

Take the first n elements of a Value in a ValueUnit

n : int

The n elements to take

Returns: ValueUnit -> ValueUnit
Example

 // returns ValueUnit ([|1N; 2N|], Mass (KiloGram 1N))
 takeFirst 2 (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N)))

takeLast n

Full Usage: takeLast n

Parameters:
    n : int - The n elements to take

Returns: ValueUnit -> ValueUnit

Take the last n elements of a Value in a ValueUnit

n : int

The n elements to take

Returns: ValueUnit -> ValueUnit
Example

 // returns ValueUnit ([|2N; 3N|], Mass (KiloGram 1N))
 takeLast 2 (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N)))

times u2 u1

Full Usage: times u2 u1

Parameters:
Returns: Unit
u2 : Unit
u1 : Unit
Returns: Unit

toBase vu

Full Usage: toBase vu

Parameters:
Returns: ValueUnit

Replace the Value in a ValueUnit to its base. For example ValueUnit(1000, mg) -> ValueUnit(1, mg)

vu : ValueUnit
Returns: ValueUnit

toBaseValue vu

Full Usage: toBaseValue vu

Parameters:
Returns: BigRational[]

Get the value of a ValueUnit as a base value. For example ValueUnit(1000, mg) -> 1

vu : ValueUnit
Returns: BigRational[]

toDelimitedString isWithUnit prec vu

Full Usage: toDelimitedString isWithUnit prec vu

Parameters:
    isWithUnit : bool - Whether to print the unit
    prec : int - The precision with which value should be printed
    vu : ValueUnit - The ValueUnit to print

Returns: string

Print a ValueUnit to a string with a given precision delimited by "#" for Value and "|" for Unit

isWithUnit : bool

Whether to print the unit

prec : int

The precision with which value should be printed

vu : ValueUnit

The ValueUnit to print

Returns: string
Example

 [| 1N/3N |] |> ValueUnit.create Units.Mass.milliGram |> toDelimitedString true 2
 // returns "#0,33# mg||"
 [| 1N/3N; 1N/5N |] |> ValueUnit.create Units.Mass.milliGram |> toDelimitedString true 2
 // returns "#0,33; 0,2# mg||"

toString hasGroup brf loc verb vu

Full Usage: toString hasGroup brf loc verb vu

Parameters:
    hasGroup : bool - When true, includes the unit group in brackets (e.g., "[Mass]"); when false, omits it
    brf : BigRational -> 'a - The function to turn a BigRational into a string
    loc : Localization - The localization to use
    verb : Verbal - The verbosity to use
    vu : ValueUnit - The ValueUnit

Returns: string
Type parameters: 'a (requires equality)

Get the user readable string version of a ValueUnit

hasGroup : bool

When true, includes the unit group in brackets (e.g., "[Mass]"); when false, omits it

brf : BigRational -> 'a

The function to turn a BigRational into a string

loc : Localization

The localization to use

verb : Verbal

The verbosity to use

vu : ValueUnit

The ValueUnit

Returns: string
Example

 toString
     true
     BigRational.toString
     Units.Dutch
     Units.Short
     (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) = "1;2;3 kg[Mass]" 
 toString
     false
     BigRational.toString
     Units.Dutch
     Units.Short
     (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))) = "1;2;3 kg"

toStringDecimalDutchLong

Full Usage: toStringDecimalDutchLong

Returns: ValueUnit -> string

Get the user readable string version in Dutch with verbosity long, value as decimal, and group annotation

Returns: ValueUnit -> string

toStringDecimalDutchShort

Full Usage: toStringDecimalDutchShort

Returns: ValueUnit -> string

Get the user readable string version in Dutch with verbosity short, value as decimal, and group annotation

Returns: ValueUnit -> string

toStringDecimalDutchShortWithPrec prec vu

Full Usage: toStringDecimalDutchShortWithPrec prec vu

Parameters:
    prec : int - The precision
    vu : ValueUnit - The ValueUnit

Returns: string

Get the user readable string version in Dutch with verbosity short, value as decimal with a fixed precision, and without group annotation. A value beyond the range of a decimal is printed as its fraction.

prec : int

The precision

vu : ValueUnit

The ValueUnit

Returns: string
Example

 toStringDecimalDutchShortWithPrec 2 (ValueUnit ([|1N/3N; 2N/3N; 3N/5N|], Mass (KiloGram 1N)))
 = "0,33;0,67;0,6 kg"

toStringDecimalEngLong

Full Usage: toStringDecimalEngLong

Returns: ValueUnit -> string

Get the user readable string version in English with verbosity long, value as decimal, and group annotation

Returns: ValueUnit -> string

toStringDecimalEngShort

Full Usage: toStringDecimalEngShort

Returns: ValueUnit -> string

Get the user readable string version in English with verbosity short, value as decimal, and group annotation

Returns: ValueUnit -> string

toStringDecimalEngShortWithoutGroup

Full Usage: toStringDecimalEngShortWithoutGroup

Returns: ValueUnit -> string

Get the user readable string version in English with verbosity short, value as decimal, without group annotation

Returns: ValueUnit -> string

toStringDutchLong

Full Usage: toStringDutchLong

Returns: ValueUnit -> string

Get the user readable string version in Dutch with verbosity long and group annotation

Returns: ValueUnit -> string

toStringDutchShort

Full Usage: toStringDutchShort

Returns: ValueUnit -> string

Get the user readable string version in Dutch with verbosity short and group annotation

Returns: ValueUnit -> string

toStringEngLong

Full Usage: toStringEngLong

Returns: ValueUnit -> string

Get the user readable string version in English with verbosity long and group annotation

Returns: ValueUnit -> string

toStringEngShort

Full Usage: toStringEngShort

Returns: ValueUnit -> string

Get the user readable string version in English with verbosity short and group annotation

Returns: ValueUnit -> string

toToken vu

Full Usage: toToken vu

Parameters:
Returns: string
vu : ValueUnit
Returns: string

toUnit vu

Full Usage: toUnit vu

Parameters:
Returns: ValueUnit

Transforms a ValueUnit to its unit. For example ValueUnit(1, mg) -> ValueUnit(1000, mg)

vu : ValueUnit
Returns: ValueUnit

toUnitValue vu

Full Usage: toUnitValue vu

Parameters:
Returns: BigRational[]

Get the value of a ValueUnit as a unit value ValueUnit(1, mg) -> 1000

vu : ValueUnit
Returns: BigRational[]

unitToReadableDutchString u

Full Usage: unitToReadableDutchString u

Parameters:
    u : Unit - The unit to convert to string

Returns: string

Get the user readable string version of a unit in Dutch short format without unit group annotation (i.e., without brackets)

u : Unit

The unit to convert to string

Returns: string
Example

 unitToReadableDutchString (Mass (KiloGram 1N)) = "kg"

unitToReadableDutchStringWithWrappers vw uw u

Full Usage: unitToReadableDutchStringWithWrappers vw uw u

Parameters:
    vw : string - A wrapper around a unit value > 1
    uw : string - A wrapper around a unit
    u : Unit - The unit to convert to string

Returns: string

Get the user readable string version of a unit in Dutch short format without unit group annotation (i.e., without brackets) and a wrapper w

vw : string

A wrapper around a unit value > 1

uw : string

A wrapper around a unit

u : Unit

The unit to convert to string

Returns: string
Example

 unitToReadableDutchString (Mass (KiloGram 1N)) = "kg"

validate fValid errMsg vu

Full Usage: validate fValid errMsg vu

Parameters:
    fValid : BigRational[] -> bool - The validator function
    errMsg : 'a - The error message
    vu : ValueUnit - The ValueUnit

Returns: Result<ValueUnit, 'a> Result.Ok vu if the values are valid, Result.Error errMsg otherwise
Type parameters: 'a

Validates the values of Value for a ValueUnit.

fValid : BigRational[] -> bool

The validator function

errMsg : 'a

The error message

vu : ValueUnit

The ValueUnit

Returns: Result<ValueUnit, 'a>

Result.Ok vu if the values are valid, Result.Error errMsg otherwise

valueCount

Full Usage: valueCount

Returns: ValueUnit -> int

Get the count of elements in a Value

Returns: ValueUnit -> int
Example

 // returns 3
 valueCount (ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N)))

valueToBase u v

Full Usage: valueToBase u v

Parameters:
Returns: RationalX

Convert a value to v to the base value of unit u. For example u = mg v = 1 -> 1/1000

u : Unit
v : RationalX
Returns: RationalX

valueToUnit u v

Full Usage: valueToUnit u v

Parameters:
Returns: RationalX

Convert a value to v to the unit value of unit u. For example u = mg v = 1 -> 1000

u : Unit
v : RationalX
Returns: RationalX

withUnit u v

Full Usage: withUnit u v

Parameters:
Returns: ValueUnit

Utility create function to allow piping v |> WithUnit u

u : Unit
v : RationalX[]
Returns: ValueUnit
Example

[| 1N; 2N; 3N |] |> withUnit (Mass (KiloGram 1N)) = ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))

withValue v u

Full Usage: withValue v u

Parameters:
Returns: ValueUnit

create a ValueUnit with syntax like u |> withValue v

v : RationalX[]
u : Unit
Returns: ValueUnit
Example

(Mass (KiloGram 1N)) |> withValue [| 1N; 2N; 3N |] = ValueUnit ([|1N; 2N; 3N|], Mass (KiloGram 1N))

zero u

Full Usage: zero u

Parameters:
Returns: ValueUnit

Create a 'zero' with unit u

u : Unit
Returns: ValueUnit

Type something to start searching.