public static Task <Either <Error, TIn> > IfNoneAsync <TIn>(this Task <Either <Error, Option <TIn> > > either, Func <Task <Either <Error, TIn> > > noneFunc) { return(either.ToAsync().Bind(r => r.MatchAsync( s => Prelude.Right <Error, TIn>(s), None: noneFunc).ToAsync() ).ToEither()); }
public static Task <Either <PowershellFailure, Option <VMStorageSettings> > > DetectVMStorageSettings( Option <TypedPsObject <VirtualMachineInfo> > optionalVmInfo, HostSettings hostSettings, Func <string, Task> reportProgress) { return(optionalVmInfo .MatchAsync( Some: s => { var namesAndId = PathToStorageNames(s.Value.Path, hostSettings.DefaultDataPath); var settings = (from resolvedPath in ResolveStorageBasePath(namesAndId.Names, hostSettings.DefaultDataPath) from storageSettings in ComparePath(resolvedPath, s.Value.Path, namesAndId.StorageIdentifier) select storageSettings); return settings.Bind(e => e.Match( Right: matchedPath => Prelude.RightAsync <PowershellFailure, VMStorageSettings>( new VMStorageSettings { StorageNames = namesAndId.Names, StorageIdentifier = namesAndId.StorageIdentifier, VMPath = matchedPath, }).ToEither(), Left: async(l) => { //current behaviour is to soft fail by disabling storage changes //however later we should add a option to strictly fail on all operations await reportProgress( "Invalid machine storage settings. Storage management is disabled."); return Prelude.Right <PowershellFailure, VMStorageSettings>( new VMStorageSettings { StorageNames = namesAndId.Names, StorageIdentifier = namesAndId.StorageIdentifier, VMPath = s.Value.Path, Frozen = true } ); })).MapAsync(r => r.ToSome().ToOption()); }, None: () => Option <VMStorageSettings> .None)); }
public Either <L, T> ToEither <L>(Func <L> Left) => IsSome ? Prelude.Right <L, T>(Value) : Prelude.Left <L, T>(Left());
public static Either <L, R> ForceRight <L, R>(this Either <L, R> either, Func <L, R> force) { return(either.BindLeft( _ => Prelude.Right <L, R>(force(_)))); }
public Either <L, T> ToEither <L>(L defaultLeftValue) => IsSome ? Prelude.Right <L, T>(Value) : Prelude.Left <L, T>(defaultLeftValue);