Last active
December 12, 2024 17:29
-
-
Save Jacoby6000/7d32f8ae3799f50fab724337dbaf2b42 to your computer and use it in GitHub Desktop.
Curried Func vs SAM interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ModdedChivalry2LauncherFactory { | |
public static Func<ModdedLaunchOptions, IEnumerable<string>, Either<ProcessLaunchFailure, Process>> CreateDefaultLauncher(IProcessLauncher, launcher, string workdir, IModManager modManager) => (moddedLaunchOpts, args) => { | |
// ... impl ... | |
} | |
} | |
public class SomeViewModel { | |
// ... | |
private Func<ModdedLaunchOptions, IEnumerable<string>, Either<ProcessLaunchFailure, Process>> Launcher { get; } | |
public SomeViewModel(Func<ModdedLaunchOptions, IEnumerable<string>, Either<ProcessLaunchFailure, Process>> launcher) { | |
Launcher = launcher; | |
} | |
public void SomeLauncherInvokingFunction() { | |
// ... | |
Launcher(foo, bar); | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ModdedLauncher = Func<ModdedLaunchOptions, IEnumerable<string>, Either<ProcessLaunchFailure, Process>> | |
public class ModdedChivalry2LauncherFactory { | |
public static ModdedLauncher CreateDefaultLauncher(IProcessLauncher, launcher, string workdir, IModManager modManager) => (moddedLaunchOpts, args) => { | |
// ... impl ... | |
} | |
} | |
public class SomeViewModel { | |
// ... | |
private ModdedLauncher Launcher { get; } | |
public SomeViewModel(ModdedLauncher launcher) { | |
Launcher = launcher; | |
} | |
public void SomeLauncherInvokingFunction() { | |
// ... | |
Launcher(foo, bar); | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IModdedChivalry2Launcher | |
{ | |
public Either<ProcessLaunchFailure, Process> Launch(ModdedLaunchOptions launchOptions, IEnumerable<string> args); | |
} | |
public class ModdedChivalry2Launcher: IModdedChivalry2Launcher { | |
private IProcessLauncher Launcher { get; } | |
private string WorkingDirectory { get; } | |
private IModManager ModManager { get; } | |
public ModdedChivalry2Launcher(IProcessLauncher, launcher, string workdir, IModManager modManager) { | |
Launcher = launcher; | |
WorkingDirectory = workdir; | |
ModManager = modManager; | |
} | |
public Either<ProcessLaunchFailure, Process> Launch(ModdedLaunchOptions launchOptions, IEnumerable<string> args) { | |
// ... impl ... | |
} | |
} | |
public class SomeViewModel { | |
// ... | |
private IModdedChivalry2Launcher Launcher { get; } | |
public SomeViewModel(IModdedChivalry2Launcher launcher) { | |
Launcher = launcher; | |
} | |
public void SomeLauncherInvokingFunction() { | |
// ... | |
Launcher.Launch(foo, bar); | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment