Use of the Result monad
To use the Result
monad open up th following library
1:
|
|
Open up the Result
operators
1:
|
|
Sample domain object Person
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: |
|
Creating a Person
, the happy path
1: 2: 3: 4: 5: 6: 7: |
|
Trying to create a Person
with empty strings fails
1: 2: 3: 4: 5: |
|
Also, the Id
cannot be too large, but creating a Name
succeeded
1: 2: 3: 4: 5: 6: |
|
A Name
cannot contain non-letter characters
1: 2: 3: 4: |
|
Creating Person
succeeded, but both Id
and Name
had trailing spaces
and where trimmed
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
namespace Informedica
namespace Informedica.GenCore
namespace Informedica.GenCore.Lib
module Result
from Informedica.GenCore.Lib
from Informedica.GenCore.Lib
module Operators
from Informedica.GenCore.Lib.ResultModule
Contains the infix operators for
* `>>=` bindL: bind a `Result` to a function that processes the contents of the result
* `<<=` bindR: bind a function that processes the contents of a result to a `Result`
* `<!>` liftR: lift a normal function to process and return a `Result`, note the function
should be a 'non failing' function without messages
* `<*>` applyR: apply a `Result` to a function that processes and returns a `Result`
from Informedica.GenCore.Lib.ResultModule
Contains the infix operators for
* `>>=` bindL: bind a `Result` to a function that processes the contents of the result
* `<<=` bindR: bind a function that processes the contents of a result to a `Result`
* `<!>` liftR: lift a normal function to process and return a `Result`, note the function
should be a 'non failing' function without messages
* `<*>` applyR: apply a `Result` to a function that processes and returns a `Result`
module WrappedString
from Informedica.GenCore.Lib
Types and functions to deal with
value primitives
from Informedica.GenCore.Lib
Types and functions to deal with
value primitives
type Dto =
{Id: string;
Name: string;}
Full name: Tutorial.Person.Dto.Dto
{Id: string;
Name: string;}
Full name: Tutorial.Person.Dto.Dto
Multiple items
Dto.Id: string
--------------------
module Id
from Informedica.GenCore.Lib.WrappedString
Type and functions that
deal with an identifier
Dto.Id: string
--------------------
module Id
from Informedica.GenCore.Lib.WrappedString
Type and functions that
deal with an identifier
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Multiple items
Dto.Name: string
--------------------
module Name
from Informedica.GenCore.Lib.WrappedString
Type and functions that represent and deal
with the `Name` type
Dto.Name: string
--------------------
module Name
from Informedica.GenCore.Lib.WrappedString
Type and functions that represent and deal
with the `Name` type
val create : id:string -> nm:string -> Dto
Full name: Tutorial.Person.Dto.create
Full name: Tutorial.Person.Dto.create
val id : string
val nm : string
module Id
from Informedica.GenCore.Lib.WrappedString
Type and functions that
deal with an identifier
from Informedica.GenCore.Lib.WrappedString
Type and functions that
deal with an identifier
module Name
from Informedica.GenCore.Lib.WrappedString
Type and functions that represent and deal
with the `Name` type
from Informedica.GenCore.Lib.WrappedString
Type and functions that represent and deal
with the `Name` type
module Message
from Informedica.GenCore.Lib
Type and functions that model and process
a `Message` to be used with the `Result` monad
from Informedica.GenCore.Lib
Type and functions that model and process
a `Message` to be used with the `Result` monad
type IdMessage =
| IdInfo of Info
| NameInfo of Info
Full name: Tutorial.Person.Message.IdMessage
| IdInfo of Info
| NameInfo of Info
Full name: Tutorial.Person.Message.IdMessage
union case IdMessage.IdInfo: Id.Message.Info -> IdMessage
module Message
from Informedica.GenCore.Lib.WrappedString.IdModule
Messsages for `Id`
from Informedica.GenCore.Lib.WrappedString.IdModule
Messsages for `Id`
Multiple items
union case Id.Message.Info.Info: string -> Id.Message.Info
--------------------
type Info = | Info of string
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Message.Info
union case Id.Message.Info.Info: string -> Id.Message.Info
--------------------
type Info = | Info of string
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Message.Info
union case IdMessage.NameInfo: Name.Message.Info -> IdMessage
module Message
from Informedica.GenCore.Lib.WrappedString.NameModule
Messsages for `Name`
from Informedica.GenCore.Lib.WrappedString.NameModule
Messsages for `Name`
Multiple items
union case Name.Message.Info.Info: string -> Name.Message.Info
--------------------
type Info = | Info of string
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Message.Info
union case Name.Message.Info.Info: string -> Name.Message.Info
--------------------
type Info = | Info of string
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Message.Info
type WarnMessage =
| IdWarn of Warning
| NameWarn of Warning
Full name: Tutorial.Person.Message.WarnMessage
| IdWarn of Warning
| NameWarn of Warning
Full name: Tutorial.Person.Message.WarnMessage
union case WarnMessage.IdWarn: Id.Message.Warning -> WarnMessage
type Warning = | Changed of string * string
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Message.Warning
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Message.Warning
union case WarnMessage.NameWarn: Name.Message.Warning -> WarnMessage
type Warning = | Changed of string * string
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Message.Warning
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Message.Warning
type ErrMessage =
| IdErr of Error
| NameErr of Error
Full name: Tutorial.Person.Message.ErrMessage
| IdErr of Error
| NameErr of Error
Full name: Tutorial.Person.Message.ErrMessage
union case ErrMessage.IdErr: Id.Message.Error -> ErrMessage
type Error =
| MinLength of string * int
| MaxLength of string * int
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Message.Error
| MinLength of string * int
| MaxLength of string * int
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Message.Error
union case ErrMessage.NameErr: Name.Message.Error -> ErrMessage
type Error =
| NoLetters of string
| MinLength of string * int
| MaxLength of string * int
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Message.Error
| NoLetters of string
| MinLength of string * int
| MaxLength of string * int
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Message.Error
type Person =
{Id: Id;
Name: Name;}
Full name: Tutorial.Person.Person
{Id: Id;
Name: Name;}
Full name: Tutorial.Person.Person
Multiple items
Person.Id: Id.Id
--------------------
module Id
from Informedica.GenCore.Lib.WrappedString
Type and functions that
deal with an identifier
Person.Id: Id.Id
--------------------
module Id
from Informedica.GenCore.Lib.WrappedString
Type and functions that
deal with an identifier
Multiple items
union case Id.Id.Id: string -> Id.Id
--------------------
type Id =
| Id of string
interface IWrappedValue<string>
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Id
Type to represent an identifier
can be any sinlge line string without
trailing or preceding spaces.
union case Id.Id.Id: string -> Id.Id
--------------------
type Id =
| Id of string
interface IWrappedValue<string>
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.Id
Type to represent an identifier
can be any sinlge line string without
trailing or preceding spaces.
Multiple items
Person.Name: Name.Name
--------------------
module Name
from Informedica.GenCore.Lib.WrappedString
Type and functions that represent and deal
with the `Name` type
Person.Name: Name.Name
--------------------
module Name
from Informedica.GenCore.Lib.WrappedString
Type and functions that represent and deal
with the `Name` type
Multiple items
union case Name.Name.Name: string -> Name.Name
--------------------
type Name =
| Name of string
interface IWrappedValue<string>
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Name
Type to represent an identifier
can be any sinlge line string without
trailing or preceding spaces.
union case Name.Name.Name: string -> Name.Name
--------------------
type Name =
| Name of string
interface IWrappedValue<string>
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.Name
Type to represent an identifier
can be any sinlge line string without
trailing or preceding spaces.
val create : id:Id.Id -> nm:Name.Name -> Person
Full name: Tutorial.Person.create
Full name: Tutorial.Person.create
val id : Id.Id
val nm : Name.Name
val fromDto : dto:Dto.Dto -> Result.Result<Person,Message.Message<Message.IdMessage,Message.WarnMessage,Message.ErrMessage> list>
Full name: Tutorial.Person.fromDto
Full name: Tutorial.Person.fromDto
val dto : Dto.Dto
module Dto
from Tutorial.Person
from Tutorial.Person
val ctId : (string -> Result.Result<Id.Id,Message.Message<Message.IdMessage,Message.WarnMessage,Message.ErrMessage> list>)
val map : (Message.Message<Id.Message.Info,Id.Message.Warning,Id.Message.Error> -> Message.Message<Message.IdMessage,Message.WarnMessage,Message.ErrMessage>)
val msg : Message.Message<Id.Message.Info,Id.Message.Warning,Id.Message.Error>
Multiple items
module Message
from Tutorial.Person
--------------------
module Message
from Informedica.GenCore.Lib
Type and functions that model and process
a `Message` to be used with the `Result` monad
module Message
from Tutorial.Person
--------------------
module Message
from Informedica.GenCore.Lib
Type and functions that model and process
a `Message` to be used with the `Result` monad
union case Message.Message.Info: 'TInfo -> Message.Message<'TInfo,'TWarn,'TErr>
val i : Id.Message.Info
union case Message.IdMessage.IdInfo: Id.Message.Info -> Message.IdMessage
union case Message.Message.Warning: 'TWarn -> Message.Message<'TInfo,'TWarn,'TErr>
val w : Id.Message.Warning
union case Message.WarnMessage.IdWarn: Id.Message.Warning -> Message.WarnMessage
union case Message.Message.Error: 'TErr -> Message.Message<'TInfo,'TWarn,'TErr>
val e : Id.Message.Error
union case Message.ErrMessage.IdErr: Id.Message.Error -> Message.ErrMessage
union case Message.Message.Except: System.Exception -> Message.Message<'TInfo,'TWarn,'TErr>
val e : System.Exception
val create : min:int -> max:int -> (string -> Result.Result<Id.Id,Message.Message<Id.Message.Info,Id.Message.Warning,Id.Message.Error>>)
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.create
Create an `Id` and return the `Result`
Full name: Informedica.GenCore.Lib.WrappedString.IdModule.create
Create an `Id` and return the `Result`
val mapMessagesR : f:('a -> 'b) -> result:Result.Result<'c,'a> -> Result.Result<'c,'b list>
Full name: Informedica.GenCore.Lib.ResultModule.mapMessagesR
Given an `Result`, map the messages to a different error type.
Full name: Informedica.GenCore.Lib.ResultModule.mapMessagesR
Given an `Result`, map the messages to a different error type.
val ctNm : (string -> Result.Result<Name.Name,Message.Message<Message.IdMessage,Message.WarnMessage,Message.ErrMessage> list>)
val map : (Message.Message<Name.Message.Info,Name.Message.Warning,Name.Message.Error> -> Message.Message<Message.IdMessage,Message.WarnMessage,Message.ErrMessage>)
val msg : Message.Message<Name.Message.Info,Name.Message.Warning,Name.Message.Error>
val i : Name.Message.Info
union case Message.IdMessage.NameInfo: Name.Message.Info -> Message.IdMessage
val w : Name.Message.Warning
union case Message.WarnMessage.NameWarn: Name.Message.Warning -> Message.WarnMessage
val e : Name.Message.Error
union case Message.ErrMessage.NameErr: Name.Message.Error -> Message.ErrMessage
val create : min:int -> max:int -> (string -> Result.Result<Name.Name,Message.Message<Name.Message.Info,Name.Message.Warning,Name.Message.Error>>)
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.create
Create an `Name` and return the `Result`
Full name: Informedica.GenCore.Lib.WrappedString.NameModule.create
Create an `Name` and return the `Result`
Dto.Dto.Id: string
Dto.Dto.Name: string
module Person
from Tutorial
from Tutorial
val create : id:string -> nm:string -> Person.Dto.Dto
Full name: Tutorial.Person.Dto.create
Full name: Tutorial.Person.Dto.create
val fromDto : dto:Person.Dto.Dto -> Result.Result<Person.Person,Message.Message<Person.Message.IdMessage,Person.Message.WarnMessage,Person.Message.ErrMessage> list>
Full name: Tutorial.Person.fromDto
Full name: Tutorial.Person.fromDto