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 3950416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:36:33+00:00 2026-05-20T01:36:33+00:00

This feels quite complicated to ask, and whilst the solution seems simple, the shear

  • 0

This feels quite complicated to ask, and whilst the solution seems simple, the shear mind bogglingness of delegates inside delegates returned from yet more delegates has caused my brain to implode in on itself.

Without further a do, I’ll explain:

The scenario is that you have translation delegates (Func[A, B]) and translation behaviours (Func[A, Func[Func[A, B], B]]).

The idea is that around a given translation, you would have a specific set of behaviours that wrap the invocation to the translation, ie- that they take in the A, feel free to do with it what they wish, pass this on to the next behaviour, whilst being able to change the returning value (B).

There is probably some monad to describe this perfectly, but perhaps some code will help more than anything.

The victims:

public class B
{

}

public class A
{

}

The behaviour delegate

public delegate Func<Func<A, B>, B> TranslationBehavior(A input);

The function which should chain them together, and return a Func that allows a translation function to be passed in and get a new translation function which is wrapped by the behaviors

static Func<Func<A, B>, Func<A, B>> Chain(IEnumerable<TranslationBehavior> behaviors)
{
    throw new NotImplementedException();
}

usage scenario

static void Main(string[] args)
{
    var behaviors = new[]
    {
        (TranslationBehavior) (inp => next => next(inp)),
        (TranslationBehavior) (inp => next => next(inp)),
        (TranslationBehavior) (inp => next => next(inp)),
    };

    var input = new A();

    var chained = Chain(behaviors);

    var output = chained(a => new B());

}

In the example code the behaviour implementations don’t do anything put call the next behaviour, and our translation implementation simply returns a new B.

The function ‘chain’ is the problem function, being able to link the behaviours together has eluded me, but to prove to myself this should actually work, I hard coded a naive solution which specifically chains three behaviours together:

static Func<Func<A, B>, Func<A, B>> Chain(IEnumerable<TranslationBehavior> behaviors)
{
    var behavior1 = (TranslationBehavior)null;
    var behavior2 = (TranslationBehavior)null;
    var behavior3 = (TranslationBehavior)null;

    return translation => input =>
        behavior1(input)(transformed1 =>
            behavior2(transformed1)(transformed2 =>
                behavior3(transformed2)(translation)
            )
        );
}

This works, but is obviously; quite useless.

Any help on this would be really useful, and any information on if this is a known pattern or monad would be really interesting, I don’t think this code code is far from being generalizable.

Thanks in advance,
Stephen.

  • 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-20T01:36:34+00:00Added an answer on May 20, 2026 at 1:36 am

    I didn’t fully understand your scenario – without some additional context, it just sounds too complicated 🙂 However, just from the types, I think the implementation you’re looking for is something like this. The trick is to add a method that works with IEnumerator and is recursive:

    Func<Func<A, B>, Func<A, B>> Chain
      (IEnumerable<TranslationBehavior> behaviors, Func<A, B> final) {
        return translation => Chain(behaviors.GetEnumerator(), translation);
    }
    
    // Recursive method that takes IEnumerator and processes one element..
    Func<A, B> Chain
      (IEnumerator<TranslationBehavior> behaviors, Func<A, B> last) {
        if (behaviors.MoveNext())
          return input => behaviors.Current(input)(Chain(behaviors, last));
        else
          return last;
    }
    

    You could add exception handling and dispose the enumerator, but this should be the right structure.

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

Sidebar

Related Questions

I feel like this is a stupid question because it seems like common sense
This question is about a general technique in SQL, that I can't quite work
OK, this feels like a question that should be easy to answer, but as
I feel like this is a dumb question and I'm missing something, but I
I feel like I should know this, but I haven't been able to figure
This is a question I intend to answer myself, but please feel free to
Disclaimer: This is not actually a programming question, but I feel the audience on
First let me say that I really feel directionless on this question. I am
Having a heckuva time with this one, though I feel I'm missing something obvious.
I've seen a few examples of RSS Feeds in ASP.NET MVC, like this ,

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.