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

  • Home
  • SEARCH
  • 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 8580877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:55:12+00:00 2026-06-11T20:55:12+00:00

I need to model an approval process. Before it was pretty simple. Two roles

  • 0

I need to model an approval process. Before it was pretty simple. Two roles had to approve something, and then we could go on to the next step:

public class Approved
{
    public string ApproverRole;
}

var approvals = Subscribe<Approved>();

var vpOfFinance = approvals.Where(e => e.ApproverRole == "Finance VP");
var vpOfSales = approvals.Where(e => e.ApproverRole == "Sales VP");

var approvedByAll = vpOfFinance.Zip(vpOfSales, Tuple.Create);

approvedByAll.Subscribe(_ => SomeInterestingBusinessProcess());

But now there is a new requirement: the number of roles required to approve something can vary:

public class ApprovalRequested
{
    public string[] Roles;
}
var approvalRequest = Subscribe<ApprovalRequested>().Take(1);
var approvals = Subscribe<Approved>();

var approvedByAll = ???;

approvedByAll.Subscribe(_ => SomeInterestingBusinessProcess());

I feel like I am missing something pretty obvious here… can anyone point me in the right direction?

Edit

To clarify: The approval process is on a per item basis. The order that the approvals can arrive in is undefined. We don’t care if one role approves an item multiple times.

  • 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-06-11T20:55:13+00:00Added an answer on June 11, 2026 at 8:55 pm

    The problem can essentially be reduced to creating a Set from a stream of values where values may be out of order or many in nature.

    If N is the cardinality of the set, we can trivially assume that the process will not proceed until at least N types of values (roles in this case) have been pushed.

    Here’s a sample solution of the Zip operator; perhaps this can get you started:

        public static IObservable<IList<T>> Zip<T>(this IList<IObservable<T>> observables)
        {
            return Observable.Create<IList<T>>(observer =>
            {
                List<List<T>> store = new List<List<T>>(Enumerable.Range(1, observables.Count).Select(_ => new List<T>()));
    
                return new CompositeDisposable(observables.Select((o, i) => 
                    o.Subscribe(value =>
                    {
                        lock (store)
                        {
                            store[i].Add(value);
    
                            if (store.All(list => list.Count > 0))
                            {
                                observer.OnNext(store.Select(list => list[0]).ToList());
                                store.ForEach(list => list.RemoveAt(0));
                            }
                        }
                    }))
                );
            });
        }
    

    Test:

            Observable.Interval(TimeSpan.FromSeconds(0.5))
                      .GroupBy(i => i % 3)
                      .Select(gr => gr.AsObservable())
                      .Buffer(3)                      
                      .SelectMany(set => set.Zip())
                      .Subscribe(v => Console.WriteLine(String.Join(",", v)));
    

    One issue here is that you may lose out on the initial values while the groups are being formed, so you might want to incorporate that by rewriting the method as IObservable<IList<T>> Zip<TKey, T>(this IGroupedObservable<TKey, T> observables).

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

Sidebar

Related Questions

Many of the properties on my model need to be represented a simple group
I need to model-bind data from textboxes generated dynamically on the client side (using
I'm working on a Web service in Django, and I need to model a
I have a need for a model(?) on my app which basically contains a
I need to load a Model in a component to save the Data of
I need to load a model, existing of +/- 20 tables from the database
I need to validate a byte[] in my model as Required but whenever I
In ActiveRecord model after_save callback I need to ROLLBACK transaction and return false. def
I need to figure out a way to set ValidateRequest at model...I understand that
Both my Rails model and controller code need to write files to the file

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.