Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lempiji committed Mar 2, 2018
1 parent 06b509c commit d23c4d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ 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](https://github.com/lempiji/rx/tree/master/examples) or [Documents](https://lempiji.github.io/rx)
Expand Down
10 changes: 10 additions & 0 deletions examples/overview/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ 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"]);
}

0 comments on commit d23c4d7

Please sign in to comment.