Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Last active December 12, 2024 17:29
Show Gist options
  • Save Jacoby6000/7d32f8ae3799f50fab724337dbaf2b42 to your computer and use it in GitHub Desktop.
Save Jacoby6000/7d32f8ae3799f50fab724337dbaf2b42 to your computer and use it in GitHub Desktop.
Curried Func vs SAM interface
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);
// ...
}
}
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);
// ...
}
}
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