GenUtils


To use String functions

Open the *string basic core library`

1: 
open Informedica.GenUtils.Lib.BCL

Now all string utility functions are accessible as String.someFunction.

Example

1: 
2: 
// Trim a string
"  Hello world.  " |> String.trim

Will return:

val it : string = "Hellow World"

To use BigRational functions

Open the GenUtils lib

1: 
open Informedica.GenUtils.Lib

Get the greatest common divisor of two bigrational string values

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
// Use 4 utility functions to create a 'string gcd'
let gcd s1 s2 = 
    let s1 = s1 |> BigRational.parse
    let s2 = s2 |> BigRational.parse
    BigRational.gcd s1 s2
    |> BigRational.toString

// Get the greatest common divisor as a string
"20" |> gcd "30" 

Returns:

val it : string = "10"

1: 
2: 
3: 
4: 
5: 
6: 
7: 
// A safe version uses tryParse and returns an empty string if failure
let gcd2 s1 s2 =
    match s1 |> BigRational.tryParse, s2 |> BigRational.tryParse with
    | Some _, Some _ -> gcd s1 s2
    | _ -> ""

"Oops" |> gcd2 "30"

Returns:

val it : string = ""

Use Continuation functions when possible

If there are continuation functions, use those instead of functions that can throw an error.

For example the BigRational.parse function had a continuation counterpart.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
type Result<'T, 'Msg> =
    | Succ of 'T
    | Fail of 'Msg list

let parse =
    let succ n = n |> Succ
    let fail m = [m] |> Fail
    BigRational.parseCont succ fail 

"blah" |> parse

Returns:

val it : Result = Fail [CannotParseString "blah"]

While

1: 
"2" |> parse

Returns:

val it : Result = Succ 2N

Thus, a success failure type monadic system can be build with continuation functions.

namespace Informedica
namespace Informedica.GenUtils
namespace Informedica.GenUtils.Lib
namespace Informedica.GenUtils.Lib.BCL
Multiple items
module String

from Informedica.GenUtils.Lib.BCL


 Helper functions for `System.String`


--------------------
module String

from Microsoft.FSharp.Core
val trim : s:System.String -> string

Full name: Informedica.GenUtils.Lib.BCL.String.trim


 Trim string `s`
val gcd : s1:string -> s2:string -> string

Full name: Tutorial.gcd
val s1 : string
val s2 : string
val s1 : BigRational
Multiple items
module BigRational

from Informedica.GenUtils.Lib


 Helper functions for `BigRational`


--------------------
type BigRational
interface IComparable
override GetHashCode : unit -> int
override ToString : unit -> string
member Denominator : BigInteger
member IsNegative : bool
member IsPositive : bool
member Numerator : BigInteger
member Sign : int
member StructuredDisplayString : string
static member Abs : BigRational -> BigRational
static member FromBigInt : BigInteger -> BigRational
static member FromInt : int -> BigRational
static member Parse : string -> BigRational
static member PowN : BigRational * int -> BigRational
static member ToBigInt : BigRational -> BigInteger
static member ToDouble : BigRational -> float
static member ToInt32 : BigRational -> int
static member One : BigRational
static member Zero : BigRational
static member ( + ) : BigRational * BigRational -> BigRational
static member ( / ) : BigRational * BigRational -> BigRational
static member ( = ) : BigRational * BigRational -> bool
static member op_Explicit : BigRational -> int
static member op_Explicit : BigRational -> BigInteger
static member op_Explicit : BigRational -> float
static member ( > ) : BigRational * BigRational -> bool
static member ( >= ) : BigRational * BigRational -> bool
static member ( <> ) : BigRational * BigRational -> bool
static member ( < ) : BigRational * BigRational -> bool
static member ( <= ) : BigRational * BigRational -> bool
static member ( * ) : BigRational * BigRational -> BigRational
static member ( - ) : BigRational * BigRational -> BigRational
static member ( ~- ) : BigRational -> BigRational
static member ( ~+ ) : BigRational -> BigRational

Full name: Microsoft.FSharp.Math.BigRational
val parse : s:string -> BigRational

Full name: Informedica.GenUtils.Lib.BigRational.parse


 Parse a string to a bigrational
val s2 : BigRational
val gcd : a:BigRational -> b:BigRational -> BigRational

Full name: Informedica.GenUtils.Lib.BigRational.gcd


 Get the greatest common divisor
 of two bigrationals `a` and `b`
val toString : v:BigRational -> string

Full name: Informedica.GenUtils.Lib.BigRational.toString


 Convert a bigrational to a string
val gcd2 : s1:string -> s2:string -> string

Full name: Tutorial.gcd2
val tryParse : s:string -> BigRational option

Full name: Informedica.GenUtils.Lib.BigRational.tryParse


 Try to parse a string and
 return `None` if it fails
 otherwise `Some` bigrational
union case Option.Some: Value: 'T -> Option<'T>
type Result<'T,'Msg> =
  | Succ of 'T
  | Fail of 'Msg list

Full name: Tutorial.Result<_,_>
union case Result.Succ: 'T -> Result<'T,'Msg>
union case Result.Fail: 'Msg list -> Result<'T,'Msg>
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val parse : (string -> Result<BigRational,BigRational.Message>)

Full name: Tutorial.parse
val succ : ('a -> Result<'a,'b>)
val n : 'a
val fail : ('a -> Result<'b,'a>)
val m : 'a
val parseCont : succ:(BigRational -> 'a) -> fail:(BigRational.Message -> 'a) -> s:string -> 'a

Full name: Informedica.GenUtils.Lib.BigRational.parseCont


 Parse a string and pass the result
 either to `succ` or `fail`
Fork me on GitHub