Simplee.Common
1.0.14
Common functionality which can be used in FSharp projects. The library exposes active patterns for comparison operations, numerals, strings. It has a Result monad and its builder for computation expressions.
InstallPackage Simplee.Common Version 1.0.14
dotnet add package Simplee.Common version 1.0.14
<PackageReference Include="Simplee.Common" Version="1.0.14" />
paket add Simplee.Common version 1.0.14
Simplee.Common
Library Simplee.Common v1.0.14 implements common functionality used by all other Simple projects.
The namespace of the library is Simplee.
Here is the main functionality exposed:
 Active patterns
 Error types
 Result monad
 2str functions
Find below more details about each class of functionality.
1. Active Patterns
The library implements different partial and complete active patterns:
1.1. Collections
You can use the following partial active patterns:
 MemberOf, NotMemberOf  these partial patterns determine if a given item is a member of a given collection.
 SeqDoesContain, SeqNotContains  these partial patterns determine whether a given collection contains or not a given item.
let is2Or3 = function
 MemberOf [2;3] > "x is a member of the collection"
 _ > "x is not a member of the collection"
let doesContain2 = function
 SeqContains 2 true > "ns does contain the item 2"
 _ > "ns does not contain the item 2"
1.2. Compare
You can use the following partial active patterns: EqualToN, LessThanN, LessOrEqualToN, GreaterThanN, GreaterOrEqualThanN.
let isSmallerThan4 = function
 LessThanN 4 > "n is less than 4"
 _ > "n is greater or equal than 4"
1.3. Numerals
There are couple of classes of active patterns related to numerals:
 Negative, NegativeOrZero, Positive, PositiveOrZero  these partial patters compare a given number to 0.
 EvenOdd  the complete pattern determines whether a given number is even or odd.
 IsMultipleOfN  this partial pattern determine whether a given number if a multiple of a given pivot N. The library exposes several convenience partial patterns for specific pivot values: IsMultipleOf2, IsMultipleOf3, IsMultipleOf4, IsMultipleOf8, IsMultipleOf10, IsMultipleOf16.
let isMultipleOf2 = function
 IsMultipleOf2 > "n is multiple of 2"
 _ > "n is not multiple of 2"
let isMultipleOf80 = functions
 IsMultipleOf8 & IsMultipleOf10 > "n is multiple of 8 and 10"
 _ > "n is not multiple of both 8 and 10"
1.3. String
The library exposes couple of classes of active patterns related to string:
 IsNullOrWhite, IsAllCaps, IndexOf, StartsWith  the partial pattern determines if a given string is null or empty or if the string has only CAPS.
 Parsing patterns  these partial patterns can be used in order to attempt parsing a given string and get an integer, or a bool, or a Date value. The patterns are: IsInt, IsBool, IsDate.
let strToInt = function
 IsInt n > "The input string is an integer"
 _ > "The input string is not an integer"
2. Error Types
The library implements an error type which is used by all other Simple projects.
The error can encapsulate any properties (operates as a property bag).
/// The property attached to an error
type ErrProperty =
 ErrProperty of nm:string * v:ErrValue
/// The error is a property bag.
type SError =
 ErrSuccess of id:ErrId * props:ErrProperty list
 ErrWarning of id:ErrId * props:ErrProperty list
 ErrError of id:ErrId * props:ErrProperty list
 ErrCritical of id:ErrId * props:ErrProperty list
The library exposes several convenience functions which allow the user create error or success instances.
let e =
1
> eid "AREA" // the error identifier (area & id)
> err // create an error
> erraddkid "corr123" // adds the correlation id
> erraddloc __SOURCE_FILE__ __LINE__ // adds the location
> erraddmsg "testing" // adds a message
// To get the string representation of an error call err2str
e > err2str
3. Result Monad
The library exposes several convenience function which can help matching the results: isROk, isRErr.
This functions match the active patterns: IsROk and IsRErr.
Also you can find couple convenience function which extract the value from success results and error from failure results: r2val and r2err
4. 2str Functions
The library comes with a set of function which generate the string representation for lists, arrays, or sequences (lst2str, arr2str, seq2str)
let s = [1;2] > arr2str (sprintf "A%d")
Assert.Equal("[A1, A2]", s)
let s = [1..10] > lst2str (sprintf "B%d")
Assert.Equal("[B1; B2; B3; B4; B5; ...]", s)
Simplee.Common
Library Simplee.Common v1.0.14 implements common functionality used by all other Simple projects.
The namespace of the library is Simplee.
Here is the main functionality exposed:
 Active patterns
 Error types
 Result monad
 2str functions
Find below more details about each class of functionality.
1. Active Patterns
The library implements different partial and complete active patterns:
1.1. Collections
You can use the following partial active patterns:
 MemberOf, NotMemberOf  these partial patterns determine if a given item is a member of a given collection.
 SeqDoesContain, SeqNotContains  these partial patterns determine whether a given collection contains or not a given item.
let is2Or3 = function
 MemberOf [2;3] > "x is a member of the collection"
 _ > "x is not a member of the collection"
let doesContain2 = function
 SeqContains 2 true > "ns does contain the item 2"
 _ > "ns does not contain the item 2"
1.2. Compare
You can use the following partial active patterns: EqualToN, LessThanN, LessOrEqualToN, GreaterThanN, GreaterOrEqualThanN.
let isSmallerThan4 = function
 LessThanN 4 > "n is less than 4"
 _ > "n is greater or equal than 4"
1.3. Numerals
There are couple of classes of active patterns related to numerals:
 Negative, NegativeOrZero, Positive, PositiveOrZero  these partial patters compare a given number to 0.
 EvenOdd  the complete pattern determines whether a given number is even or odd.
 IsMultipleOfN  this partial pattern determine whether a given number if a multiple of a given pivot N. The library exposes several convenience partial patterns for specific pivot values: IsMultipleOf2, IsMultipleOf3, IsMultipleOf4, IsMultipleOf8, IsMultipleOf10, IsMultipleOf16.
let isMultipleOf2 = function
 IsMultipleOf2 > "n is multiple of 2"
 _ > "n is not multiple of 2"
let isMultipleOf80 = functions
 IsMultipleOf8 & IsMultipleOf10 > "n is multiple of 8 and 10"
 _ > "n is not multiple of both 8 and 10"
1.3. String
The library exposes couple of classes of active patterns related to string:
 IsNullOrWhite, IsAllCaps, IndexOf, StartsWith  the partial pattern determines if a given string is null or empty or if the string has only CAPS.
 Parsing patterns  these partial patterns can be used in order to attempt parsing a given string and get an integer, or a bool, or a Date value. The patterns are: IsInt, IsBool, IsDate.
let strToInt = function
 IsInt n > "The input string is an integer"
 _ > "The input string is not an integer"
2. Error Types
The library implements an error type which is used by all other Simple projects.
The error can encapsulate any properties (operates as a property bag).
/// The property attached to an error
type ErrProperty =
 ErrProperty of nm:string * v:ErrValue
/// The error is a property bag.
type SError =
 ErrSuccess of id:ErrId * props:ErrProperty list
 ErrWarning of id:ErrId * props:ErrProperty list
 ErrError of id:ErrId * props:ErrProperty list
 ErrCritical of id:ErrId * props:ErrProperty list
The library exposes several convenience functions which allow the user create error or success instances.
let e =
1
> eid "AREA" // the error identifier (area & id)
> err // create an error
> erraddkid "corr123" // adds the correlation id
> erraddloc __SOURCE_FILE__ __LINE__ // adds the location
> erraddmsg "testing" // adds a message
// To get the string representation of an error call err2str
e > err2str
3. Result Monad
The library exposes several convenience function which can help matching the results: isROk, isRErr.
This functions match the active patterns: IsROk and IsRErr.
Also you can find couple convenience function which extract the value from success results and error from failure results: r2val and r2err
4. 2str Functions
The library comes with a set of function which generate the string representation for lists, arrays, or sequences (lst2str, arr2str, seq2str)
let s = [1;2] > arr2str (sprintf "A%d")
Assert.Equal("[A1, A2]", s)
let s = [1..10] > lst2str (sprintf "B%d")
Assert.Equal("[B1; B2; B3; B4; B5; ...]", s)
Release Notes
Added 2str function for lists, arrays, and sequences.
Dependencies

.NETCoreApp 2.0
 FSharp.Core (>= 4.3.4)
GitHub Usage
This package is not used by any popular GitHub repositories.
Version History
Version  Downloads  Last updated  

1.0.14  265  3/20/2018  
1.0.13  257  3/18/2018  
1.0.12  216  3/15/2018  
1.0.11  247  3/2/2018  
1.0.10  262  3/1/2018  
1.0.9  238  2/27/2018  
1.0.8  265  2/27/2018  
1.0.7  252  2/26/2018  
1.0.6  229  2/26/2018  
1.0.5  248  2/21/2018  
1.0.4  260  2/11/2018  
1.0.3  270  2/11/2018  
1.0.2  270  1/29/2018  
1.0.1  277  1/26/2018  
1.0.0  252  1/26/2018 