Skip to content
Reactive Extensions for D Programming Language
D
Branch: dev
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmarks/subject-put
docs
examples
source/rx
.gitattributes
.gitignore
.travis.yml Update compiler versions May 3, 2019
CONTRIBUTING.md
LICENSE Edit README and add LICENSE file Sep 14, 2016
README.md
deps-lock.txt Update diff Jun 16, 2019
deps.dot Update diff Jun 16, 2019
deps.png
deps.svg
deps.txt
docs.json
dub.json
dub.selections.json

README.md

Reactive Extensions for D Programming Language

Dub version MIT License Build Status codecov

Overview

This is a library like Rx.NET for asynchronous or event based programs, based on the concept of OutputRange.

The operators' name is based on std.algorithm and ReactiveX.

Example

import rx;
import std.conv : to;
import std.range : iota, put;

void main()
{
    // create own source of int
    auto subject = new SubjectObject!int;

    // define result array
    string[] result;

    // define pipeline and subscribe
    // sequence: source -> filter by even -> map to string -> join to result
    auto disposable = subject.filter!(n => n % 2 == 0).map!(o => to!string(o))
        .doSubscribe!(text => result ~= text);

    // set unsubscribe on exit
    // it is not necessary in this simple example,
    // but in many cases you should call dispose to prevent memory leaks.
    scope (exit)
        disposable.dispose();

    // put values to source. 
    put(subject, iota(10));

    // result is like this
    assert(result == ["0", "2", "4", "6", "8"]);
}

And more examples or Documents

Usage

Setting dependencies in dub.json

{
    ...
    "dependencies": {
        "rx": "~>0.10.0"
    }
}

or dub.sdl

dependency "rx" version="~>0.10.0"

Concepts

Basic interfaces

All operators are written using template and struct for optimization. this example is a binary interface like std.range.interfaces.

//module rx.disposable
interface Disposable
{
    void dispose();
}

//module rx.observer
interface Observer(E) : OutputRange!E
{
    //void put(E obj); //inherits from OutputRange!E
    void completed();
    void failure(Exception e);
}

//module rx.observable
interface Observable(E)
{
    alias ElementType = E;
    Disposable subscribe(Observer!E observer);
}

Supported Compilers

Supported compilers are dmd and ldc that latest 3 versions.

License

This library is under the MIT License.
Some code is borrowed from Rx.NET.

Contributing

Issue and PullRequest are welcome! 😃

Refer to CONTRIBUTING.md for details.

Development

Build and unittest

git clone https://github.com/lempiji/rx
cd rx
dub test

Update documents

Use https://github.com/adamdruppe/adrdox

Future work

  • generic observable factory
    • create, start, timer, interval
  • more subjects
    • publish, connectable
  • more algorithms
    • window, multicast
  • more test
  • more documents
You can’t perform that action at this time.