2

I'm using language-ext in a C# .NET Core project and I'm able to do partial application on an existing function:

Func<T1, T2, T3, T4, R> originalFun = /* ... */;

Func<T4, R> partialFun = par(originalFun, paramT1, paramT2, paramT3);

Now, I'd like to augment parameter list in order to match an existing signature, where additional parameters would just be ignored. In plain language I can write:

Func<U1, U2, T4, R> augmentedFun = (_, __, paramT4) => partialFun(paramT4);

I wonder if there any "standard" tool available in that library to achieve that, much in the same way as par replaces manual lambda expressions. TA

superjos
  • 12,189
  • 6
  • 89
  • 134

1 Answers1

1

I don't think there is some existing LanguageExt helper function to allow that style par and similar helpers use and there might be a good reason to not add this:

One would probably need a lot of those helper functions to allow having relevant arguments at any position. What about this use case:

Func<T1, U1, U2, R> augmentedFun = (paramT1, _, __) = someFunction2(paramT1)

and this

Func<U1, T2, U2, R> augmentedFun = (_, paramT2, __) = someFunction3(paramT2)

and this one:

Func<T1, U1, T3, R> augmentedFun = (paramT1, _, paramT3) = someFunc4(paramT1, paramT3)

The lambda expression in your working solution makes it very clear what your intent is, i.e. which args to omit.

BTW: Would be great if C# would let us omit dummy variables _ and __ here or use wildcard. I found a discussion on this (throwaway variables, discards) here and here. But wildcard support is limited to tuple deconstruction like var (_, _) = (3,4); in C# 7.

If C# would use tuples same way it uses function argument lists many things would be better, especially in LanguageExt context.

stb
  • 772
  • 5
  • 15