© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
LukeJ

✅ Typed delegates in maps (LanguageExt)

Hello. I'm currently doing some functional programming with the LanguageExt package. I've been going through and adding an environment to my effectful methods, which has left me with a bit of a problem. I have 3 different turn methods that I store in in map, like so
private static readonly Map<ConsoleKey, TurnMethod> TurnMethodBinding = Map(
        (ConsoleKey.Z, (TurnMethod)UserTurn),
        (ConsoleKey.X, AITurn),
        (ConsoleKey.C, AITurnInPhases)
    );
private static readonly Map<ConsoleKey, TurnMethod> TurnMethodBinding = Map(
        (ConsoleKey.Z, (TurnMethod)UserTurn),
        (ConsoleKey.X, AITurn),
        (ConsoleKey.C, AITurnInPhases)
    );

This uses the delegate TurnMethod defined as
public delegate Eff<RT, Either<TurnReturn, ExitConsole>> TurnMethod<RT>(FieldState fieldState, User player) where RT : struct, HasIO<RT>;
public delegate Eff<RT, Either<TurnReturn, ExitConsole>> TurnMethod<RT>(FieldState fieldState, User player) where RT : struct, HasIO<RT>;

As you can see though, this is typed with RT, which got added to the signature when adding an environment to the method. This causes the Map problems, saying there's an incorrect number of type paramaters. I have no idea how to do that map with the type paramater included though. Any ideas?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Delegates in C#
C#CC# / help
13mo ago
✅ LanguageExt bind if
C#CC# / help
3y ago
Delegates
C#CC# / help
2y ago
❔ Delegates
C#CC# / help
3y ago