Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:28:17+00:00 2026-05-26T00:28:17+00:00

I have an interface like this: interface IProcessor{ IObservable<Item> Process(Item item); } I have

  • 0

I have an interface like this:

interface IProcessor{
    IObservable<Item> Process(Item item);
}

I have an array of workers:

IProcessor[] _workers = ....

I want to pass an item through all the workers:

var ret = Observable.Return(item);
for (var i = 0; i < _workers.Length; i++)
{
    int index = i;
    ret = ret
        .SelectMany(r => _workers[index].Process(r))
    ;
}
return ret;

I’m not too happy with how this looks — is there a cleaner way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:28:17+00:00Added an answer on May 26, 2026 at 12:28 am

    This works for me:

    IObservable<Item> ret = _workers.Aggregate(
        Observable.Return(item),
        (rs, w) =>
            from r in rs
            from p in w.Process(r)
            select p);
    

    Please keep in mind that this kind of aggregation of observables – both in your question and in my answer – can cause memory issues (i.e. stack overflow) quickly. In my tests I could get 400 workers working, but 500 caused a crash.

    You’re better off changing your IProcessor to not use observables and implement your observable like this:

    interface IProcessor{
        Item Process(Item item);
    }
    
    var f =
        _workers.Aggregate<IProcessor, Func<Item, Item>>(
                i => i,
                (fs, p) => i => p.Process(fs(i)));
    
    var ret = Observable.Start(() => f(item), Scheduler.ThreadPool);
    

    With this approach I can get over 20,000 nested workers before a stack overflow and the results are almost instantaneous up to that level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method on an interface that looks like this and I want
I have a interface member like this. AppInterface.cs ObjLocation[] ArrayLocations { get; } App.cs
I have a scene, called testScene, it works like this: @interface testScene : myScene
Let's say I have a class that implements the IDisposable interface. Something like this:
I have a XIB set up like in this screenshot: alt text http://emberapp.com/jxpx777/images/interface-builder/sizes/m.png File's
I'd like to have one interface for all my grid related tasks.The tasks implement
I have an interface like this public interface IField<T> extends IsSerializable { public String
Say I have an interface like this: public interface ISomeInterface { ... } I
I have an interface defined like this @interface PageViewController : UIImageView { ... }
I have an interface like this: public interface IFoo { int A {get;} int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.