rx ~support-2.077.0
Reactive Extensions for D Programming Language.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Reactive Extensions for D Programming Language
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()
{
auto subject = new SubjectObject!int;
string[] result;
auto disposable = subject.filter!(n => n % 2 == 0).map!(o => to!string(o))
.doSubscribe!(text => result ~= text);
scope (exit)
disposable.dispose();
put(subject, iota(10));
assert(result == ["0", "2", "4", "6", "8"]);
}
And more examples or Documents
Usage
Setting dependencies in dub.json
{
...
"dependencies": {
"rx": "~>0.1.0"
}
}
or dub.sdl
dependency "rx" version="~>0.1.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);
}
License
This library is under the MIT License. Some code is borrowed from Rx.NET.
Future work
- more subjects
- publish, replay
- more algorithms
- more test
- more documents
- ~support-2.077.0 released 7 years ago
- lempiji/rx
- github.com/lempiji/rx
- MIT
- Copyright © 2015, lempiji