lempiji / rx

Reactive Extensions for D Programming Language
MIT License
53 stars 8 forks source link

Return type of filter!(...) #28

Closed Robert-M-Muench closed 5 years ago

Robert-M-Muench commented 6 years ago
Subject!int sub = new SubjectObject!int;
auto filtered = sub.filter!(n => n % 2 == 0);

I can get my code to work using auto and filter! but I'm wondering what the explicit return type of filter!(...) is? The type suggested is FilterObservable, but this one can't be used in my code.

Subject!int sub = new SubjectObject!int;
FilterObservable filtered = sub.filter!(n => n % 2 == 0);

This gives: Error: undefined identifier FilterObservable

lempiji commented 6 years ago

Some operators return the voldemort type like std.algorithm and std.range.

Where do you want to declare a type?

There are also methods like this if you want to unify the type to the interface.

'Observable!T f = filtered.observableObject!T()'

Robert-M-Muench commented 6 years ago

I need the types because I want to declare class/struct members.

I now used:

alias typeof(osStream.WMStream.filter!(wm => wm.message == WM_DESTROY)) wmDestroyType;

So I'm able to reference the type at several places. But it's more a trial and error process to come-up with the correct declaration.

lempiji commented 5 years ago

I made the FilterObservable public in `v 0.11. 0 '. https://github.com/lempiji/rx/commit/61707e2c0e0cb0096541ad92b6785cb16898283b

However, it may be difficult to manually specify several template parameters one by one.

Given the cost of writing everything by hand, I think your method is a good solution. If you're comfortable wrapping in interfaces or classes, try using the observableObject function.

If there is anything else, please ask me again.