So .. to pick one extension method you can add your own version of the extension methods within your application that just delegate to the external implementations you want to use. These extensions have to be at the same or a higher level in the namespace hierarchy as the calling code so the compiler will select them first and (following the rules above) the two ambiguous versions in the LanguageExt
namespace will never be considered.
For the original example, where I wanted to use the extension for Task<Validation<FAIL, C>>
the extensions can just delegate to the generated source code in LanguageExt.Transformers
:
using System;
using System.Threading.Tasks;
using LanguageExt;
namespace YourApplication;
public static class BindDisambiguationExtensions
{
public static Task<Validation<FAIL, B>> Select<FAIL, A, B>(
this Task<Validation<FAIL, A>>self,
Func<A, B> f) =>
ValidationT_AsyncSync_Extensions.Select(self, f);
public static Task<Validation<FAIL, C>> SelectMany<FAIL, A, B, C>(
this Task<Validation<FAIL, A>> self,
Func<A, Task<Validation<FAIL, B>>> bind,
Func<A, B, C> project) =>
ValidationT_AsyncSync_Extensions.SelectMany(self, bind, project);
}
If you are using stacked monads in LanguageExt
then you may encounter similar issues with different combinations of types (eg Task<Either<
), in which case you can find the source-code for the extensions class name of the particular combination of stacked monads you are using and delegate to that.
Note: I have also posted this as an answer to a stackoverflow question.
Comments
Comments are closed