rx 0.0.2
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
The is a library like the Rx.NET, for the asynchronous or event-based programs on OutputRange concept.
Basic concept 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);
}
Example
import rx;
import std.algorithm : equal;
import std.array : appender;
import std.conv : to;
void main()
{
auto subject = new SubjectObject!int;
auto pub = subject
.filter!(n => n % 2 == 0)
.map!(o => to!string(o));
auto buf = appender!(string[]);
auto disposable = pub.subscribe(buf);
foreach (i; 0 .. 10)
{
subject.put(i); //fire some event
}
auto result = buf.data;
assert(equal(result, ["0", "2", "4", "6", "8"])); //receive some event
}
License
This library is under the MIT License.
Some code is borrowed from Rx.NET.
Future work
- more algorithms
- reduce(aggregate)
- zip
- takeUntil
- skipUntil
- more utilities
- generators
- more test
- more documents
- 0.0.2 released 8 years ago
- lempiji/rx
- github.com/lempiji/rx
- MIT
- Copyright © 2015, lempiji