YarikTH / ureact

Functional reactive programming library for c++
Boost Software License 1.0
155 stars 10 forks source link

Add some kind of `observe_and_call` #113

Closed YarikTH closed 1 year ago

YarikTH commented 1 year ago

Description

Currently ureact::observe only allows to subscribe to the future changes of observable value. But in case of ureact::signal there is also current value that could be also needed in passed functor. Currently for the same user should call functor manually with the initial value.

ureact::context ctx;

auto src = ureact::make_var( ctx, 1 );

auto i_want_each_value = [](int i){};

i_want_each_value( src.get() );
ureact::observe( src, i_want_each_value );

Need to research API of analogs if they came up with a good names or approaches for such cases.

YarikTH commented 1 year ago

It's easier to just introduce enum class observe_policy:

enum class observe_policy
{
    skip_current.     ///< default behavior. Notify only when signal value has changed
    notify_current   ///< notify current value, then when signal value has changed
};

So we don't need to introduce new adaptors like observe_and_call, tap_and_call, but only provide additional argument for signal observations.