Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I do a two-level sort of an incoming signal using ReactiveCocoa?
    primarykey
    data
    text
    <p>I have been tooling around with ReactiveCocoa and I've come upon an interesting problem. I can envision any number of ugly, stateful solutions, but I'm pretty confident there is an elegant, functional way that's just not materializing in my head for whatever reason. Maybe you can help!</p> <p>The input signal here is two part strings, like <code>"&lt;letter&gt;,&lt;number&gt;"</code>. The desired sort rules are that for a given letter, the input values should appear at the output in the order of <code>&lt;number&gt;</code> (i.e. <code>A,2</code> should never appear before <code>A,1</code>) and that across all letters <code>&lt;letter&gt;</code> outputs should not violate alpha order. (i.e. no string starting with <code>B</code> should appear until at least one string starting with <code>A</code> has appeared.) Other than as dictated by those rules, the expectation is that things will arrive on the output in the order they are submitted to the input.</p> <p>Consider the following code:</p> <pre><code>RACSubject* input = [RACSubject subject]; RACSignal* output = [input &lt;SOME CHAIN OF SIGNAL FUNCTIONS&gt;]; [output subscribeNext:^(id x) { NSLog(@"(%@)",x); }]; [input sendNext: @"A,2"]; // Expect no output [input sendNext: @"B,4"]; // Expect no output [input sendNext: @"B,2"]; // Expect no output [input sendNext: @"B,1"]; // Expect no output [input sendNext: @"A,1"]; // Expect output: (A,1) (A,2) (B,1) (B,2) // Note: (A,1) (B,1) (B,2) (A,2) would *not* be right because A,2 appeared on the input before B,1 [input sendNext: @"C,1"]; // Expect output: (C,1) [input sendNext: @"B,3"]; // Expect output: (B,3) (B,4) [input sendNext: @"C,3"]; // Expect no output [input sendNext: @"C,2"]; // Expect output: (C,2) (C,3) </code></pre> <p>Also output should be produced "eagerly". It's not useful if I have to wait until the input signal is completed before seeing output (unless, of course, the sorting rules dictate that that's the case, i.e. if <code>A,1</code> came last)</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload