system.reactive - Rx debouncing inputs -


I have to cancel the input stream.

Wait for 5 seconds on the state's first incident 1 and see if the last state was 1. Only I have a constant sign.

  (time) 0-1-2-3-4-5-6-7 -8-9 (state) 0-0-0-0-0-1-0-1 -1-1-1 (Results) - & gt; 1   

Here is an example of a non-static signal.

  (time) 0-1-2-3-4-5-6--7-8-9 (state) 0-0-0-0-0-1-0-0 -0-0 (results) - & gt; 0   

I tried to use a buffer, but buffer has fixed the starting point and I need to wait 5 seconds for my first event.

Really take your needs

The first incident of state 1 I have to wait for 5 seconds and to confirm that the final position was also 1. Only I have a constant sign.

I can come in some ways to solve this problem. To clarify my assumptions, you want to push the last value that produces 5 seconds after the first occurrence of 1. The result will be the output of the previous value, despite one or 0 or 1 (i.e. any other values.

)). (10) Select. Select (i = & gt; {if (i == 5 || i == 7} I == 9) {return 1;} else {return 0;}}}); // should produce 1; //.Select(i=>{if(i==5 || i == 7) {return1;} and {return 0;}}); Should produce // 0;

See all the options sequence below to share. To share a sequence securely in Rx we publish () and connect it I use automatic connecting through the RefCount () operator.

  var sharedSource = source.Publish (). RefCount ();   

1) In this solution we first assume 1, and then buffer selection of sequence values ​​in buffer size of 5 seconds. We only take these buffers first, once we receive this buffer, we get the last value and press it. If the buffer is empty, then I think we push one up because the last value was '1' which started with buffer running.

  sharedSource.Where (state => state == 1). (1) .SelectMany (_ = & gt; Shared resources. Buffer (timespace.fruceseconds (5)) Take (1)). Select (buffer = & gt; {if (buffer Any ()) {return buffer last ();} and {return1;}}). Dump (); 2) In this solution, after taking a valid value (1), only take the approach to listen and then all agree until the timer triggers the termination. . From here we take the final produced.  
  var fromFirstValid = sharedSource.SkipWhile (state => state == 0); From First Valid.tecuntil (Firstvalidate.Tech (1). Chosen fair (_ => Observation timer (TimespenFrossseconds (5))) .lalylist (1) dump (); 3) In this solution I use the window operator to create a single window which opens when the first value of '1' is and closes when the time is up to 5 seconds. Then we just assume the final  
  shared resources Indo (shared resource. Where (state => state == 1), _ = & gt; overview timer (timespace.formsconds (5)). SelectionMany (window => window le lease (1) ). (1) dump ();   

So many ways of skin-a-cat

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -