Reaction 0.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Reaction --version 0.5.0                
NuGet\Install-Package Reaction -Version 0.5.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="Reaction" Version="0.5.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Reaction --version 0.5.0                
#r "nuget: Reaction, 0.5.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 Reaction as a Cake Addin
#addin nuget:?package=Reaction&version=0.5.0

// Install Reaction as a Cake Tool
#tool nuget:?package=Reaction&version=0.5.0                

re·ac·tion

Reaction is a lightweight Async Reactive (Rx) library for F# targeting Fable. This means that the code may be transpiled to JavaScript, and thus the same F# code may be used both client and server side for full stack software development.

Currently a playground project for experimenting with async reactive functional programming (Async Observables) in F#. The project is heavily inspired by aioreactive.

See Fable Reaction for Elmish-ish use of Reaction.

Install

paket add Reaction --project <project>

Async Observables

Reaction is an implementation of Async Observable. The difference between an "Async Observable" and an "Observable" is that with "Async Observables" you need to await operations such as Subscribe, OnNext, OnError, OnCompleted. This enables Subscribe to await async operations i.e setup network connections, and observers may finally await side effects such as writing to disk (observers are all about side-effects right?).

Reaction is built upon simple functions instead of classes and the traditional Rx interfaces. Some of the operators uses mailbox processors (actors) to implement the observer pipeline in order to avoid locks and mutables. This makes the code more Fable friendly. Here are the core types:

type Notification<'a> =
    | OnNext of 'a
    | OnError of exn
    | OnCompleted

type AsyncDisposable = unit -> Async<unit>
type AsyncObserver<'a> = Notification<'a> -> Async<unit>
type AsyncObservable<'a> = AsyncObserver<'a> -> Async<AsyncDisposable>

Usage

open Reaction

let main = async {
    let mapper x =
        x * 10

    let xs = single 42 |> map mapper
    let obv n =
        match n with
        | OnNext x -> printfn "OnNext: %d" x
        | OnError ex -> printfn "OnError: %s" ex.ToString()
        | OnCompleted -> printfn "OnCompleted"

    let! subscription = xs.SubscribeAsync obv
}

Async.Start main

Operators

The following parameterized async observerable returning functions (operators) are currently supported. Other operators may be implemented on-demand, but there are currently no plans to make this into a full featured Rx implementation.

  • empty : () → AsyncObservable<'a>
  • single : 'a → AsyncObservable<'a>
  • fail : exn → AsyncObservable<'a>
  • ofSeq : seq< 'a> → AsyncObservable<'a>
  • map : ('a → 'b) → AsyncObservable<'a> → AsyncObservable<'b>
  • mapi : ('a*int → 'b) → AsyncObservable<'a> → AsyncObservable<'b>
  • mapAsync : ('a → Async<'b>) → AsyncObservable<'a> → AsyncObservable<'b>
  • mapiAsync : ('a*int → Async<'b>) → AsyncObservable<'a> → AsyncObservable<'b>
  • filter : ('a → Async<bool>) → AsyncObservable<'a> → AsyncObservable<'a>
  • filterAsync : ('a → bool) → AsyncObservable<'a> → AsyncObservable<'a>
  • distinctUntilChanged : AsyncObservable<'a> → AsyncObservable<'a>
  • scan : 's → ('s → 'a → 's) → AsyncObservable<'a> → AsyncObservable<'s>
  • scanAsync : 's → ('s → 'a → Async<'s>) → AsyncObservable<'a> → AsyncObservable<'s>
  • merge : AsyncObservable<AsyncObservable<'a>> → AsyncObservable<'a>
  • switchLatest : AsyncObservable<AsyncObservable<'a>> → AsyncObservable<'a>
  • flatMap : ('a → AsyncObservable<'b>) → AsyncObservable<'a> → AsyncObservable<'b>
  • flatMapi : ('a*int → AsyncObservable<'b>) → AsyncObservable<'a> → AsyncObservable<'b>
  • flatMapAsync : ('a → Async<AsyncObservable<'b>>) → AsyncObservable<'a> → AsyncObservable<'b>
  • flatMapiAsync : ('a*int → Async<AsyncObservable<'b>>) → AsyncObservable<'a> → AsyncObservable<'b>
  • concat : seq<AsyncObservable<'a>> → AsyncObservable<'a>
  • startWith : seq<'a> → AsyncObservable<'a> → AsyncObservable<'a>
  • delay : int → AsyncObservable<'a> → AsyncObservable<'a>
  • debounce : int → AsyncObservable<'a> → AsyncObservable<'a>
  • combineLatest : AsyncObservable<'b> → AsyncObservable<'a> → AsyncObservable<'a*'b>
  • withLatestFrom : AsyncObservable<'b> → AsyncObservable<'a> → AsyncObservable<'a*'b>
  • catch : (exn → AsyncObservable<'a>) → AsyncObservable<'a> → AsyncObservable<'a>
  • groupBy : ('a → 'g) → AsyncObservable<'a> → AsyncObservable<AsyncObservable<'a>>
  • zipSeq : seq<'b> → AsyncObservable<'a> → AsyncObservable<'a*'b>
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 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 Reaction:

Package Downloads
Reaction.Giraffe

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 2,123 10/20/2018
0.13.1 1,421 10/1/2018
0.13.0 820 9/30/2018
0.12.3 969 9/27/2018
0.11.0 931 9/20/2018
0.10.0 793 9/15/2018
0.9.1 991 9/5/2018
0.9.0 731 9/5/2018
0.8.2 948 9/4/2018
0.8.1 786 9/2/2018
0.8.0 895 9/2/2018
0.7.0 773 9/1/2018
0.6.0 753 9/1/2018
0.5.0 743 8/31/2018
0.4.0 889 8/29/2018
0.3.0 719 8/28/2018
0.2.0 718 8/26/2018
0.1.0 800 8/15/2018