Simplee.Control 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Simplee.Control --version 1.0.0                
NuGet\Install-Package Simplee.Control -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Simplee.Control" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Simplee.Control --version 1.0.0                
#r "nuget: Simplee.Control, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Simplee.Control as a Cake Addin
#addin nuget:?package=Simplee.Control&version=1.0.0

// Install Simplee.Control as a Cake Tool
#tool nuget:?package=Simplee.Control&version=1.0.0                

Koko |> Simple.Control

Library Simplee.Control v1.0.0 implements common control functionality used by all other Simple projects. The namespace of the library is Simplee.Control.

Here is a list of monads exposed by the library:

  1. Reader monad
  2. State monad
  3. Writer monad

1. Reader Monad

The library exposes a Reader monad, which is a function that reads from a given environment and returns a value.

type Reader<'e, 'a> = Reader of ('e -> 'a)

The main functions related to the Reader monad are rdrrun which executes a reader and/or a reader flow, rdrbind which binds a reader to a function, rdr which is the computation expression builder.

You can use the reader in a functional way:

    let readRun         = Reader (fun _ -> true)
    let readCfgLocal    = Reader (fun _ -> "local configuration")
    let readCfgRemote   = Reader (fun _ -> "remote configuration")

    let readCfg = function
        | true  -> readCfgLocal 
        | _     -> readCfgRemote

    let flow = rdrbind readRun readCfg
    let res = () |> rdrrun flow

    Assert.Equal("local configuration", res)

You can use the built-in computation expression builder as well, for imperative programming:

    let readRun         = Reader (fun _ -> false)
    let readCfgLocal    = Reader (fun _ -> "local configuration")
    let readCfgRemote   = Reader (fun _ -> "remote configuration")

    let flow = reader {
        let! b = readRun

        match b with
        | true -> return! readCfgLocal
        | _    -> return! readCfgRemote
    }

    let res = () |> rdrrun flow
    Assert.Equal("remote configuration", res)

2. State Monad

The library exposes a State monad, which is a function that transition from a given state to another state while generating also a value at the end of the transition.

type State<'a, 's> = State of ('s -> 'a * 's)

The main functions related to the State monad are sttrun which executes a state transition and/or a state flow, sttbind which binds a state to a function, state which is the computation expression builder.

You can use the state in a functional way:

    let t0 = State (fun n -> (n,   n+1))
    let t1 = State (fun n -> (n+1, n+1))

    let fn n = 
        match n % 2 with
        | 0 -> t0
        | _ -> t1

    let flow = sttbind t0 fn
    let res = 1 |> sttrun flow |> fst

    // We run t0 from 1 to 2, the returned value should be 1 + 0
    // Since 1 % 2 is 1 
    // We run t1 from 2 to 3, the returned value should be 2 + 1

    Assert.Equal(3, res)

You can use the built-in computation expression builder as well, for imperative programming:

    let t0 = State (fun n -> (n,   n+1))
    let t1 = State (fun n -> (n+1, n+1))

    let flow = state {
        let! r = t0            
            
        match r % 2 with
        | 0 -> return! t0
        | _ -> return! t1
    }

    let res = 1 |> sttrun flow |> fst
    Assert.Equal(3, res)

3. Writer Monad

The library exposes a Writer monad, which is a function which does not take any arguments and returns the new accumulated log and a value.

type Writer<'a, 'l> = Writer of (unit -> 'a * 'l)

The main functions related to the Writer monad are wrtrun which executes a writer transition and/or a state flow, wrtbind which binds a writer to a function, wrt which is the computation expression builder. There are several convenience functions such wrttell which adds a new log entry without returning any value, wrtpass which can apply a function returned in the result to the log entries.

The writer implementations must expose two static function: Unit and Combine.

You can use the built-in computation expression builder as well, for imperative programming:

    type LogWriter<'TLog> =
        | Log of list<'TLog>

        /// Returns the empty list
        static member Unit = [] |> Log

        /// Combines two logs
        static member Combine (Log a, Log b) = b |> List.append a |> Log

    let logs (Log lst) = lst

    let logmsg m = [m] |> Log |> wrttell 

    let flow = wrt {
        do! logmsg "Begin processing files"
        do! logmsg "Ended processing files"
    }

    let ls = flow |> wrtrun |> snd |> logs
    Assert.Equal(2, ls |> List.length)


A. Installation

You can install the Simplee.Control nuget package by using one of the following commands:

PM> Install-Package Simplee.Control -Version 1.0.0
> dotnet add package Simplee.Control --version 1.0.0
> paket add Simplee.Control --version 1.0.0
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Simplee.Control:

Package Downloads
Simplee.Data

FSharp library which implements different data structures.

GitHub repositories

This package is not used by any popular GitHub repositories.

Initial release of the library