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

The Archive Base Latest Questions

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

I’m learning F# and I got to thinking. You can chain operations from normal

  • 0

I’m learning F# and I got to thinking. You can chain operations from normal operators, such as

let aChainedFunc = List.map func >> List.reduce func

then later you can go let result = aChainedFunc aList to get the results of those same operations, allowing some nice reuse in a short amount of code.

But, what if you have a C# object where you want to invoke methods from that object, but pre-build the chain similarly to the F# example above?

Obviously this requires an object that can do normal a.Method1().Method2().Method3() to make it work, but is there a way to sanely set this up to allow this to work without building a method where you pass it in instead?

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

    If you wanted to create sequence of static method calls (or extension method calls), say SomeType.Method1, SomeType.Method2 and OtherType.Method3, then you can write a C# method Compose that behaves similarly to the >> operator in C#:

    Func<T, R> Compose<T, U, R>(Func<T, U> f1, Func<U, R> f2) {
      return v => f2(f2(v));
    }
    

    Then you should be able to write something like:

    Compose(SomeType.Method1, SomeType.Method2).Compose(OtherType.Method3); // ...
    

    Note that this will work only for methods taking single argument (but you could define overloaded versions that take multiple arguments and the compiler should be able to infer them).

    If you’re calling instance methods then there is no syntax for referring just to the method – you need some expression to invoke the method on. A little lighter way than writing a method would be to write a lambda expression:

    // Chain multiple operations
    Func<SomeType, SomeType> composed = v => v.Method1().Method2().Method3();
    // Use chained operation two times
    var v1 = composed(foo1);
    var v2 = composed(foo2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have text I am displaying in SIlverlight that is coming from a CMS
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.